home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / packages / texinfmt.el.z / texinfmt.el
Encoding:
Text File  |  1998-05-21  |  112.6 KB  |  3,064 lines

  1. ;;; texinfmt.el --- format Texinfo files into Info files.
  2.  
  3. ;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993 Free Software
  4. ;; Foundation, Inc.
  5.  
  6. ;; Maintainer: Robert J. Chassell <bug-texinfo@prep.ai.mit.edu>
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  22. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  23. ;; 02111-1307, USA.
  24.  
  25. ;;; Synched up with: FSF 19.34.
  26.  
  27. ;;; Code:
  28.  
  29. ;;; Emacs lisp functions to convert Texinfo files to Info files.
  30.  
  31. (defvar texinfmt-version "2.34 of 7 June 1995")
  32.  
  33. ;;; Variable definitions
  34.  
  35. (require 'texinfo)          ; So `texinfo-footnote-style' is defined.
  36. (require 'texnfo-upd)       ; So `texinfo-section-types-regexp' is defined.
  37.  
  38. (defvar texinfo-format-syntax-table nil)
  39.  
  40. (defvar texinfo-vindex)
  41. (defvar texinfo-findex)
  42. (defvar texinfo-cindex)
  43. (defvar texinfo-pindex)
  44. (defvar texinfo-tindex)
  45. (defvar texinfo-kindex)
  46. (defvar texinfo-last-node)
  47. (defvar texinfo-node-names)
  48. (defvar texinfo-enclosure-list)
  49. (defvar texinfo-alias-list)
  50.  
  51. (defvar texinfo-command-start)
  52. (defvar texinfo-command-end)
  53. (defvar texinfo-command-name)
  54. (defvar texinfo-defun-type)
  55. (defvar texinfo-last-node-pos)
  56. (defvar texinfo-stack)
  57. (defvar texinfo-short-index-cmds-alist)
  58. (defvar texinfo-short-index-format-cmds-alist)
  59. (defvar texinfo-format-filename)
  60. (defvar texinfo-footnote-number)
  61. (defvar texinfo-start-of-header)
  62. (defvar texinfo-end-of-header)
  63. (defvar texinfo-raisesections-alist)
  64. (defvar texinfo-lowersections-alist)
  65.  
  66. ;;; Syntax table
  67.  
  68. (if texinfo-format-syntax-table
  69.     nil
  70.   (setq texinfo-format-syntax-table (make-syntax-table))
  71.   (modify-syntax-entry ?\" " " texinfo-format-syntax-table)
  72.   (modify-syntax-entry ?\\ " " texinfo-format-syntax-table)
  73.   (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table)
  74.   (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table)
  75.   (modify-syntax-entry ?\[ "." texinfo-format-syntax-table)
  76.   (modify-syntax-entry ?\] "." texinfo-format-syntax-table)
  77.   (modify-syntax-entry ?\( "." texinfo-format-syntax-table)
  78.   (modify-syntax-entry ?\) "." texinfo-format-syntax-table)
  79.   (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table)
  80.   (modify-syntax-entry ?} "){" texinfo-format-syntax-table)
  81.   (modify-syntax-entry ?\' "." texinfo-format-syntax-table))
  82.  
  83.  
  84. ;;; Top level buffer and region formatting functions
  85.  
  86. ;;;###autoload
  87. (defun texinfo-format-buffer (&optional notagify)
  88.   "Process the current buffer as texinfo code, into an Info file.
  89. The Info file output is generated in a buffer visiting the Info file
  90. names specified in the @setfilename command.
  91.  
  92. Non-nil argument (prefix, if interactive) means don't make tag table
  93. and don't split the file if large.  You can use Info-tagify and
  94. Info-split to do these manually."
  95.   (interactive "P")
  96.   (let ((lastmessage "Formatting Info file..."))
  97.     (message lastmessage)
  98.     (texinfo-format-buffer-1)
  99.     (if notagify
  100.         nil
  101.       (if (> (buffer-size) 30000)
  102.           (progn
  103.             (message (setq lastmessage "Making tags table for Info file..."))
  104.             (Info-tagify)))
  105.       (if (> (buffer-size) 100000)
  106.           (progn
  107.             (message (setq lastmessage "Splitting Info file..."))
  108.             (Info-split))))
  109.     (message (concat lastmessage
  110.                      (if (interactive-p) "done.  Now save it." "done.")))))
  111.  
  112. (defvar texinfo-region-buffer-name "*Info Region*"
  113.   "*Name of the temporary buffer used by \\[texinfo-format-region].")
  114.  
  115. ;;;###autoload
  116. (defun texinfo-format-region (region-beginning region-end)
  117.   "Convert the current region of the Texinfo file to Info format.
  118. This lets you see what that part of the file will look like in Info.
  119. The command is bound to \\[texinfo-format-region].  The text that is
  120. converted to Info is stored in a temporary buffer."
  121.   (interactive "r")
  122.   (message "Converting region to Info format...")
  123.   (let (texinfo-command-start
  124.         texinfo-command-end
  125.         texinfo-command-name
  126.         texinfo-vindex
  127.         texinfo-findex
  128.         texinfo-cindex
  129.         texinfo-pindex
  130.         texinfo-tindex
  131.         texinfo-kindex
  132.         texinfo-stack
  133.         (texinfo-format-filename "")
  134.         texinfo-example-start
  135.         texinfo-last-node-pos
  136.         texinfo-last-node
  137.         texinfo-node-names
  138.         (texinfo-footnote-number 0)
  139.         last-input-buffer
  140.         (fill-column-for-info fill-column)
  141.         (input-buffer (current-buffer))
  142.         (input-directory default-directory)
  143.         (header-text "")
  144.         (header-beginning 1)
  145.         (header-end 1))
  146.     
  147. ;;; Copy lines between beginning and end of header lines, 
  148. ;;;    if any, or else copy the `@setfilename' line, if any.
  149.     (save-excursion
  150.         (save-restriction
  151.           (widen)
  152.           (goto-char (point-min))
  153.           (let ((search-end (save-excursion (forward-line 100) (point))))
  154.             (if (or
  155.                  ;; Either copy header text.
  156.                  (and 
  157.                   (prog1 
  158.                       (search-forward tex-start-of-header search-end t)
  159.                     (forward-line 1)
  160.                     ;; Mark beginning of header.
  161.                     (setq header-beginning (point)))
  162.                   (prog1 
  163.                       (search-forward tex-end-of-header nil t)
  164.                     (beginning-of-line)
  165.                     ;; Mark end of header
  166.                     (setq header-end (point))))
  167.                  ;; Or copy @filename line.
  168.                  (prog2
  169.                   (goto-char (point-min))
  170.                   (search-forward "@setfilename" search-end t)
  171.                   (beginning-of-line)
  172.                   (setq header-beginning (point))
  173.                   (forward-line 1)
  174.                   (setq header-end (point))))
  175.                 
  176.                 ;; Copy header  
  177.                 (setq header-text
  178.                       (buffer-substring
  179.                        (min header-beginning region-beginning)
  180.                        header-end))))))
  181.  
  182. ;;; Find a buffer to use.
  183.     (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
  184.     (erase-buffer)
  185.     ;; Insert the header into the buffer.
  186.     (insert header-text)
  187.     ;; Insert the region into the buffer.
  188.     (insert-buffer-substring
  189.      input-buffer
  190.      (max region-beginning header-end)
  191.      region-end)
  192.     ;; Make sure region ends in a newline.
  193.     (or (= (preceding-char) ?\n)
  194.         (insert "\n"))
  195.     
  196.     (goto-char (point-min))
  197.     (texinfo-mode)
  198.     (message "Converting region to Info format...")
  199.     (setq fill-column fill-column-for-info)
  200.     ;; Install a syntax table useful for scanning command operands.
  201.     (set-syntax-table texinfo-format-syntax-table)
  202.  
  203.     ;; Insert @include files so `texinfo-raise-lower-sections' can
  204.     ;; work on them without losing track of multiple
  205.     ;; @raise/@lowersections commands. 
  206.     (while (re-search-forward "^@include" nil t)
  207.       (setq texinfo-command-end (point))
  208.       (let ((filename (concat input-directory
  209.                               (texinfo-parse-line-arg))))
  210.         (re-search-backward "^@include")
  211.         (delete-region (point) (save-excursion (forward-line 1) (point)))
  212.         (message "Reading included file: %s" filename)
  213.         (save-excursion
  214.           (save-restriction
  215.             (narrow-to-region
  216.              (point)
  217.              (+ (point) (car (cdr (insert-file-contents filename)))))
  218.             (goto-char (point-min))
  219.             ;; Remove `@setfilename' line from included file, if any,
  220.             ;; so @setfilename command not duplicated.
  221.             (if (re-search-forward 
  222.                  "^@setfilename" (save-excursion (forward-line 100) (point)) t)
  223.                 (progn
  224.                   (beginning-of-line)
  225.                   (delete-region
  226.                    (point) (save-excursion (forward-line 1) (point)))))))))
  227.  
  228.     ;; Raise or lower level of each section, if necessary.
  229.     (goto-char (point-min))
  230.     (texinfo-raise-lower-sections)
  231.     ;; Append @refill to appropriate paragraphs for filling.
  232.     (goto-char (point-min))
  233.     (texinfo-append-refill)
  234.     ;; If the region includes the effective end of the data,
  235.     ;; discard everything after that.
  236.     (goto-char (point-max))
  237.     (if (re-search-backward "^@bye" nil t)
  238.         (delete-region (point) (point-max)))
  239.     ;; Make sure buffer ends in a newline.
  240.     (or (= (preceding-char) ?\n)
  241.         (insert "\n"))
  242.     ;; Don't use a previous value of texinfo-enclosure-list.
  243.     (setq texinfo-enclosure-list nil)
  244.     (setq texinfo-alias-list nil)
  245.  
  246.     (goto-char (point-min))
  247.     (if (looking-at "\\\\input[ \t]+texinfo")
  248.         (delete-region (point) (save-excursion (forward-line 1) (point))))
  249.  
  250.     ;; Insert Info region title text.
  251.     (goto-char (point-min))
  252.     (if (search-forward 
  253.          "@setfilename" (save-excursion (forward-line 100) (point)) t)
  254.         (progn
  255.           (setq texinfo-command-end (point))
  256.           (beginning-of-line)
  257.           (setq texinfo-command-start (point))
  258.           (let ((arg (texinfo-parse-arg-discard)))
  259.             (insert " "
  260.               texinfo-region-buffer-name
  261.               " buffer for:  `") 
  262.             (insert (file-name-nondirectory (expand-file-name arg)))
  263.             (insert "',        -*-Text-*-\n")))
  264.       ;; Else no `@setfilename' line
  265.       (insert " "
  266.               texinfo-region-buffer-name
  267.               " buffer                       -*-Text-*-\n"))
  268.     (insert "produced by `texinfo-format-region'\n"
  269.             "from a region in: "
  270.             (if (buffer-file-name input-buffer)
  271.                   (concat "`"
  272.                           (file-name-sans-versions
  273.                            (file-name-nondirectory
  274.                             (buffer-file-name input-buffer)))
  275.                           "'")
  276.                 (concat "buffer `" (buffer-name input-buffer) "'"))
  277.               "\nusing `texinfmt.el' version "
  278.               texinfmt-version
  279.               ".\n\n")
  280.  
  281.     ;; Now convert for real.
  282.     (goto-char (point-min))
  283.     (texinfo-format-scan)
  284.     (goto-char (point-min))
  285.     
  286.     (message "Done.")))
  287.  
  288.  
  289. ;;; Primary internal formatting function for the whole buffer.
  290.  
  291. (defun texinfo-format-buffer-1 ()
  292.   (let (texinfo-format-filename
  293.         texinfo-example-start
  294.         texinfo-command-start
  295.         texinfo-command-end
  296.         texinfo-command-name
  297.         texinfo-last-node
  298.         texinfo-last-node-pos
  299.         texinfo-vindex
  300.         texinfo-findex
  301.         texinfo-cindex
  302.         texinfo-pindex
  303.         texinfo-tindex
  304.         texinfo-kindex
  305.         texinfo-stack
  306.         texinfo-node-names
  307.         (texinfo-footnote-number 0)
  308.         last-input-buffer
  309.         outfile
  310.         (fill-column-for-info fill-column)
  311.         (input-buffer (current-buffer))
  312.         (input-directory default-directory))
  313.     (setq texinfo-enclosure-list nil)
  314.     (setq texinfo-alias-list nil)
  315.     (save-excursion
  316.       (goto-char (point-min))
  317.       (or (search-forward "@setfilename" nil t)
  318.           (error "Texinfo file needs an `@setfilename FILENAME' line."))
  319.       (setq texinfo-command-end (point))
  320.       (setq outfile (texinfo-parse-line-arg)))
  321.     (find-file outfile)
  322.     (texinfo-mode)
  323.     (setq fill-column fill-column-for-info)
  324.     (set-syntax-table texinfo-format-syntax-table)
  325.     (erase-buffer)
  326.     (insert-buffer-substring input-buffer)
  327.     (message "Converting %s to Info format..." (buffer-name input-buffer))
  328.     
  329.     ;; Insert @include files so `texinfo-raise-lower-sections' can
  330.     ;; work on them without losing track of multiple
  331.     ;; @raise/@lowersections commands. 
  332.     (goto-char (point-min))
  333.     (while (re-search-forward "^@include" nil t)
  334.       (setq texinfo-command-end (point))
  335.       (let ((filename (concat input-directory
  336.                               (texinfo-parse-line-arg))))
  337.         (re-search-backward "^@include")
  338.         (delete-region (point) (save-excursion (forward-line 1) (point)))
  339.         (message "Reading included file: %s" filename)
  340.         (save-excursion
  341.           (save-restriction
  342.             (narrow-to-region
  343.              (point)
  344.              (+ (point) (car (cdr (insert-file-contents filename)))))
  345.             (goto-char (point-min))
  346.             ;; Remove `@setfilename' line from included file, if any,
  347.             ;; so @setfilename command not duplicated.
  348.             (if (re-search-forward 
  349.                  "^@setfilename"
  350.                  (save-excursion (forward-line 100) (point)) t)
  351.                 (progn
  352.                   (beginning-of-line)
  353.                   (delete-region
  354.                    (point) (save-excursion (forward-line 1) (point)))))))))
  355.     ;; Raise or lower level of each section, if necessary.
  356.     (goto-char (point-min))
  357.     (texinfo-raise-lower-sections)
  358.     ;; Append @refill to appropriate paragraphs
  359.     (goto-char (point-min))
  360.     (texinfo-append-refill)
  361.     (goto-char (point-min))
  362.     (search-forward "@setfilename")
  363.     (beginning-of-line)
  364.     (delete-region (point-min) (point))
  365.     ;; Remove @bye at end of file, if it is there.
  366.     (goto-char (point-max))
  367.     (if (search-backward "@bye" nil t)
  368.         (delete-region (point) (point-max)))
  369.     ;; Make sure buffer ends in a newline.
  370.     (or (= (preceding-char) ?\n)
  371.         (insert "\n"))
  372.     ;; Scan the whole buffer, converting to Info format.
  373.     (texinfo-format-scan)
  374.     ;; Return data for indices.
  375.     (goto-char (point-min))
  376.     (list outfile
  377.           texinfo-vindex texinfo-findex texinfo-cindex
  378.           texinfo-pindex texinfo-tindex texinfo-kindex)))
  379.  
  380.  
  381. ;;; Perform non-@-command file conversions: quotes and hyphens
  382.  
  383. (defun texinfo-format-convert (min max)
  384.   ;; Convert left and right quotes to typewriter font quotes.
  385.   (goto-char min)
  386.   (while (search-forward "``" max t)
  387.     (replace-match "\""))
  388.   (goto-char min)
  389.   (while (search-forward "''" max t)
  390.     (replace-match "\""))
  391.   ;; Convert three hyphens in a row to two.
  392.   (goto-char min)
  393.   (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t)
  394.     (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning
  395.     2)))))
  396.  
  397.  
  398. ;;; Handle paragraph filling
  399.  
  400. (defvar texinfo-no-refill-regexp
  401.   "^@\\(example\\|smallexample\\|lisp\\|smalllisp\\|display\\|format\\|flushleft\\|flushright\\|menu\\|titlepage\\|iftex\\|ifhtml\\|tex\\|html\\)"
  402.   "Regexp specifying environments in which paragraphs are not filled.")
  403.  
  404. (defvar texinfo-part-of-para-regexp
  405.   "^@\\(b{\\|bullet{\\|cite{\\|code{\\|emph{\\|equiv{\\|error{\\|expansion{\\|file{\\|i{\\|inforef{\\|kbd{\\|key{\\|lisp{\\|minus{\\|point{\\|print{\\|pxref{\\|r{\\|ref{\\|result{\\|samp{\\|sc{\\|t{\\|TeX{\\|today{\\|var{\\|w{\\|xref{\\)"
  406.   "Regexp specifying @-commands found within paragraphs.")
  407.  
  408. (defun texinfo-append-refill ()
  409.   "Append @refill at end of each paragraph that should be filled.
  410. Do not append @refill to paragraphs within @example and similar environments.  
  411. Do not append @refill to paragraphs containing @w{TEXT} or @*."
  412.  
  413.   ;; It is necessary to append @refill before other processing because
  414.   ;; the other processing removes information that tells Texinfo
  415.   ;; whether the text should or should not be filled.
  416.   
  417.   (while (< (point) (point-max))
  418.     (let ((refill-blank-lines "^[ \t\n]*$")
  419.           (case-fold-search nil))       ; Don't confuse @TeX and @tex....
  420.       (beginning-of-line)
  421.       ;; 1. Skip over blank lines;
  422.       ;;    skip over lines beginning with @-commands, 
  423.       ;;    but do not skip over lines
  424.       ;;      that are no-refill environments such as @example or
  425.       ;;      that begin with within-paragraph @-commands such as @code.
  426.       (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines))
  427.                   (not (looking-at 
  428.                         (concat
  429.                          "\\(" 
  430.                          texinfo-no-refill-regexp
  431.                          "\\|" 
  432.                          texinfo-part-of-para-regexp
  433.                          "\\)")))
  434.                   (< (point) (point-max)))
  435.         (forward-line 1))
  436.       ;; 2. Skip over @example and similar no-refill environments.
  437.       (if (looking-at texinfo-no-refill-regexp)
  438.           (let ((environment
  439.                  (buffer-substring (match-beginning 1) (match-end 1))))
  440.             (progn (re-search-forward (concat "^@end " environment) nil t)
  441.                    (forward-line 1)))
  442.         ;; 3. Do not refill a paragraph containing @w or @*
  443.         (if  (or
  444.               (>= (point) (point-max))
  445.               (re-search-forward
  446.                "@w{\\|@\\*" (save-excursion (forward-paragraph) (point)) t))
  447.             ;; Go to end of paragraph and do nothing.
  448.             (forward-paragraph) 
  449.           ;; 4. Else go to end of paragraph and insert @refill
  450.           (forward-paragraph)
  451.           (forward-line -1)
  452.           (end-of-line)
  453.           (delete-region
  454.            (point)
  455.            (save-excursion (skip-chars-backward " \t") (point)))
  456.           ;; `looking-at-backward' not available in v. 18.57
  457.           ;; (if (not (looking-at-backward "@refill\\|@bye")) ;)
  458.           (if (not (re-search-backward
  459.                     "@refill\\|@bye"
  460.                     (save-excursion (beginning-of-line) (point))
  461.                     t))
  462.               (insert "@refill"))
  463.           (forward-line 1))))))
  464.  
  465.  
  466. ;;; Handle `@raisesections' and `@lowersections' commands
  467.  
  468. ;; These commands change the hierarchical level of chapter structuring
  469. ;; commands. 
  470. ;;    
  471. ;; @raisesections changes @subsection to @section,
  472. ;;                        @section    to @chapter,
  473. ;;                        etc.
  474. ;;
  475. ;; @lowersections changes @chapter    to @section
  476. ;;                        @subsection to @subsubsection,
  477. ;;                        etc.
  478. ;;
  479. ;; An @raisesections/@lowersections command changes only those
  480. ;; structuring commands that follow the @raisesections/@lowersections
  481. ;; command.
  482. ;;
  483. ;; Repeated @raisesections/@lowersections continue to raise or lower
  484. ;; the heading level.
  485. ;; 
  486. ;; An @lowersections command cancels an @raisesections command, and
  487. ;; vice versa.
  488. ;;
  489. ;; You cannot raise or lower "beyond" chapters or subsubsections, but
  490. ;; trying to do so does not elicit an error---you just get more
  491. ;; headings that mean the same thing as you keep raising or lowering
  492. ;; (for example, after a single @raisesections, both @chapter and
  493. ;; @section produce chapter headings).
  494.  
  495. (defun texinfo-raise-lower-sections ()
  496.   "Raise or lower the hierarchical level of chapters, sections, etc. 
  497.  
  498. This function acts according to `@raisesections' and `@lowersections'
  499. commands in the Texinfo file.
  500.  
  501. For example, an `@lowersections' command is useful if you wish to
  502. include what is written as an outer or standalone Texinfo file in
  503. another Texinfo file as an inner, included file.  The `@lowersections'
  504. command changes chapters to sections, sections to subsections and so
  505. on.
  506.  
  507. @raisesections changes @subsection to @section,
  508.                        @section    to @chapter,
  509.                        @heading    to @chapheading,
  510.                        etc.
  511.  
  512. @lowersections changes @chapter    to @section,
  513.                        @subsection to @subsubsection,
  514.                        @heading    to @subheading,
  515.                        etc.
  516.  
  517. An `@raisesections' or `@lowersections' command changes only those
  518. structuring commands that follow the `@raisesections' or
  519. `@lowersections' command.
  520.  
  521. An `@lowersections' command cancels an `@raisesections' command, and
  522. vice versa.
  523.  
  524. Repeated use of the commands continue to raise or lower the hierarchical
  525. level a step at a time.
  526.  
  527. An attempt to raise above `chapters' reproduces chapter commands; an
  528. attempt to lower below subsubsections reproduces subsubsection
  529. commands."
  530.   
  531.   ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el';
  532.   ;; it is a regexp matching chapter, section, other headings
  533.   ;; (but not the top node).
  534.  
  535.   (let (type (level 0))
  536.     (while 
  537.         (re-search-forward
  538.          (concat
  539.           "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\("
  540.           texinfo-section-types-regexp
  541.           "\\)\\)")
  542.          nil t)
  543.       (beginning-of-line)
  544.       (save-excursion (setq type (read (current-buffer))))
  545.       (cond 
  546.        
  547.        ;; 1. Increment level
  548.        ((eq type '@raisesections)
  549.         (setq level (1+ level))
  550.         (delete-region
  551.          (point) (save-excursion (forward-line 1) (point))))
  552.        
  553.        ;; 2. Decrement level
  554.        ((eq type '@lowersections)
  555.         (setq level (1- level))
  556.         (delete-region
  557.          (point) (save-excursion (forward-line 1) (point))))
  558.        
  559.        ;; Now handle structuring commands
  560.        ((cond
  561.          
  562.          ;; 3. Raise level when positive
  563.          ((> level 0)
  564.           (let ((count level)
  565.                 (new-level type))
  566.             (while (> count 0)
  567.               (setq new-level
  568.                     (cdr (assq new-level texinfo-raisesections-alist)))
  569.               (setq count (1- count)))
  570.             (kill-word 1)
  571.             (insert (symbol-name new-level))))
  572.          
  573.          ;; 4. Do nothing except move point when level is zero
  574.          ((= level 0) (forward-line 1))
  575.          
  576.          ;; 5. Lower level when positive
  577.          ((< level 0)
  578.           (let ((count level)
  579.                 (new-level type))
  580.             (while (< count 0)
  581.               (setq new-level
  582.                     (cdr (assq new-level texinfo-lowersections-alist)))
  583.               (setq count (1+ count)))
  584.             (kill-word 1)
  585.             (insert (symbol-name new-level))))))))))
  586.  
  587. (defvar texinfo-raisesections-alist
  588.   '((@chapter . @chapter)             ; Cannot go higher
  589.     (@unnumbered . @unnumbered)
  590.  
  591.     (@majorheading . @majorheading)
  592.     (@chapheading . @chapheading)
  593.     (@appendix . @appendix)
  594.     
  595.     (@section . @chapter)
  596.     (@unnumberedsec . @unnumbered)
  597.     (@heading . @chapheading)
  598.     (@appendixsec . @appendix)
  599.     
  600.     (@subsection . @section)
  601.     (@unnumberedsubsec . @unnumberedsec)
  602.     (@subheading . @heading)
  603.     (@appendixsubsec . @appendixsec)
  604.     
  605.     (@subsubsection . @subsection)
  606.     (@unnumberedsubsubsec . @unnumberedsubsec)
  607.     (@subsubheading . @subheading)
  608.     (@appendixsubsubsec . @appendixsubsec))
  609.   "*An alist of next higher levels for chapters, sections. etc.
  610. For example, section to chapter, subsection to section.
  611. Used by `texinfo-raise-lower-sections'.
  612. The keys specify types of section; the values correspond to the next
  613. higher types.")
  614.  
  615. (defvar texinfo-lowersections-alist
  616.   '((@chapter . @section)  
  617.     (@unnumbered . @unnumberedsec)
  618.     (@majorheading . @heading)
  619.     (@chapheading . @heading)
  620.     (@appendix . @appendixsec)
  621.     
  622.     (@section . @subsection)
  623.     (@unnumberedsec . @unnumberedsubsec)
  624.     (@heading . @subheading)
  625.     (@appendixsec . @appendixsubsec)
  626.     
  627.     (@subsection . @subsubsection)
  628.     (@unnumberedsubsec . @unnumberedsubsubsec)
  629.     (@subheading . @subsubheading)
  630.     (@appendixsubsec . @appendixsubsubsec)
  631.     
  632.     (@subsubsection . @subsubsection) ; Cannot go lower.
  633.     (@unnumberedsubsubsec . @unnumberedsubsubsec)
  634.     (@subsubheading . @subsubheading)
  635.     (@appendixsubsubsec . @appendixsubsubsec))
  636.   "*An alist of next lower levels for chapters, sections. etc.
  637. For example, chapter to section, section to subsection.
  638. Used by `texinfo-raise-lower-sections'.
  639. The keys specify types of section; the values correspond to the next
  640. lower types.")
  641.  
  642.  
  643. ;;; Perform those texinfo-to-info conversions that apply to the whole input
  644. ;;; uniformly.
  645.  
  646. (defun texinfo-format-scan ()
  647.   (texinfo-format-convert (point-min) (point-max))
  648.   ;; Scan for @-commands.
  649.   (goto-char (point-min))
  650.   (while (search-forward "@" nil t)
  651.     (if (looking-at "[@{}^'` *\"?!]")
  652.         ;; Handle a few special @-followed-by-one-char commands.
  653.         (if (= (following-char) ?*)
  654.             (progn
  655.               ;; remove command
  656.               (delete-region (1- (point)) (1+ (point)))
  657.               ;; insert return if not at end of line;
  658.               ;; else line is already broken.
  659.               (if (not (= (following-char) ?\n))
  660.                   (insert ?\n)))      
  661.           ;; The other characters are simply quoted.  Delete the @.
  662.           (delete-char -1)
  663.           (forward-char 1))
  664.       ;; @ is followed by a command-word; find the end of the word.
  665.       (setq texinfo-command-start (1- (point)))
  666.       (if (= (char-syntax (following-char)) ?w)
  667.           (forward-word 1)
  668.         (forward-char 1))
  669.       (setq texinfo-command-end (point))
  670.       ;; Handle let aliasing
  671.       (setq texinfo-command-name
  672.         (let (trial
  673.           (cmdname 
  674.            (buffer-substring
  675.             (1+ texinfo-command-start) texinfo-command-end)))
  676.           (while (setq trial (assoc cmdname texinfo-alias-list))
  677.         (setq cmdname (cdr trial)))
  678.             (intern cmdname)))
  679.       ;; Call the handler for this command.
  680.       (let ((enclosure-type
  681.              (assoc
  682.               (symbol-name texinfo-command-name)
  683.               texinfo-enclosure-list)))
  684.         (if enclosure-type
  685.             (progn
  686.               (insert
  687.                (car (car (cdr enclosure-type))) 
  688.                (texinfo-parse-arg-discard)
  689.                (car (cdr (car (cdr enclosure-type)))))
  690.               (goto-char texinfo-command-start))
  691.           (let ((cmd (get texinfo-command-name 'texinfo-format)))
  692.             (if cmd (funcall cmd) (texinfo-unsupported)))))))
  693.   
  694.   (cond (texinfo-stack
  695.          (goto-char (nth 2 (car texinfo-stack)))
  696.          (error "Unterminated @%s" (car (car texinfo-stack))))))
  697.  
  698. (put 'begin 'texinfo-format 'texinfo-format-begin)
  699. (defun texinfo-format-begin ()
  700.   (texinfo-format-begin-end 'texinfo-format))
  701.  
  702. (put 'end 'texinfo-format 'texinfo-format-end)
  703. (defun texinfo-format-end ()
  704.   (texinfo-format-begin-end 'texinfo-end))
  705.  
  706. (defun texinfo-format-begin-end (prop)
  707.   (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
  708.   (let ((cmd (get texinfo-command-name prop)))
  709.     (if cmd (funcall cmd)
  710.       (texinfo-unsupported))))
  711.  
  712. ;;; Parsing functions
  713.  
  714. (defun texinfo-parse-line-arg ()
  715.   (goto-char texinfo-command-end)
  716.   (let ((start (point)))
  717.     (cond ((looking-at " ")
  718.            (skip-chars-forward " ")
  719.            (setq start (point))
  720.            (end-of-line)
  721.            (skip-chars-backward " ")
  722.            (delete-region (point) (progn (end-of-line) (point)))
  723.            (setq texinfo-command-end (1+ (point))))
  724.           ((looking-at "{")
  725.            (setq start (1+ (point)))
  726.            (forward-list 1)
  727.            (setq texinfo-command-end (point))
  728.            (forward-char -1))
  729.           (t
  730.            (error "Invalid texinfo command arg format")))
  731.     (prog1 (buffer-substring start (point))
  732.            (if (eolp) (forward-char 1)))))
  733.  
  734. (defun texinfo-parse-expanded-arg ()
  735.   (goto-char texinfo-command-end)
  736.   (let ((start (point))
  737.         marker)
  738.     (cond ((looking-at " ")
  739.            (skip-chars-forward " ")
  740.            (setq start (point))
  741.            (end-of-line)
  742.            (setq texinfo-command-end (1+ (point))))
  743.           ((looking-at "{")
  744.            (setq start (1+ (point)))
  745.            (forward-list 1)
  746.            (setq texinfo-command-end (point))
  747.            (forward-char -1))
  748.           (t
  749.            (error "Invalid texinfo command arg format")))
  750.     (setq marker (move-marker (make-marker) texinfo-command-end))
  751.     (texinfo-format-expand-region start (point))
  752.     (setq texinfo-command-end (marker-position marker))
  753.     (move-marker marker nil)
  754.     (prog1 (buffer-substring start (point))
  755.            (if (eolp) (forward-char 1)))))
  756.  
  757. (defun texinfo-format-expand-region (start end)
  758.   (save-restriction
  759.     (narrow-to-region start end)
  760.     (let (texinfo-command-start
  761.           texinfo-command-end
  762.           texinfo-command-name
  763.           texinfo-stack)
  764.       (texinfo-format-scan))
  765.     (goto-char (point-max))))
  766.  
  767. (defun texinfo-parse-arg-discard ()
  768.   (prog1 (texinfo-parse-line-arg)
  769.          (texinfo-discard-command)))
  770.  
  771. (defun texinfo-discard-command ()
  772.   (delete-region texinfo-command-start texinfo-command-end))
  773.  
  774. (defun texinfo-optional-braces-discard ()
  775.   "Discard braces following command, if any."
  776.   (goto-char texinfo-command-end)
  777.   (let ((start (point)))
  778.     (cond ((looking-at "[ \t]*\n"))     ; do nothing
  779.           ((looking-at "{")             ; remove braces, if any
  780.            (forward-list 1)
  781.            (setq texinfo-command-end (point)))
  782.           (t
  783.            (error
  784.             "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
  785.     (delete-region texinfo-command-start texinfo-command-end)))
  786.  
  787. (defun texinfo-format-parse-line-args ()
  788.   (let ((start (1- (point)))
  789.         next beg end
  790.         args)
  791.     (skip-chars-forward " ")
  792.     (while (not (eolp))
  793.       (setq beg (point))
  794.       (re-search-forward "[\n,]")
  795.       (setq next (point))
  796.       (if (bolp) (setq next (1- next)))
  797.       (forward-char -1)
  798.       (skip-chars-backward " ")
  799.       (setq end (point))
  800.       (setq args (cons (if (> end beg) (buffer-substring beg end))
  801.                        args))
  802.       (goto-char next)
  803.       (skip-chars-forward " "))
  804.     (if (eolp) (forward-char 1))
  805.     (setq texinfo-command-end (point))
  806.     (nreverse args)))
  807.  
  808. (defun texinfo-format-parse-args ()
  809.   (let ((start (1- (point)))
  810.         next beg end
  811.         args)
  812.     (search-forward "{")
  813.     (save-excursion
  814.       (texinfo-format-expand-region 
  815.        (point)
  816.        (save-excursion (up-list 1) (1- (point)))))
  817.     ;; The following does not handle cross references of the form:
  818.     ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
  819.     ;; re-search-forward finds the first right brace after the second
  820.     ;; comma. 
  821.     (while (/= (preceding-char) ?\})
  822.       (skip-chars-forward " \t\n")
  823.       (setq beg (point))
  824.       (re-search-forward "[},]")
  825.       (setq next (point))
  826.       (forward-char -1)
  827.       (skip-chars-backward " \t\n")
  828.       (setq end (point))
  829.       (cond ((< beg end)
  830.              (goto-char beg)
  831.              (while (search-forward "\n" end t)
  832.                (replace-match " "))))
  833.       (setq args (cons (if (> end beg) (buffer-substring beg end))
  834.                        args))
  835.       (goto-char next))
  836.     (if (eolp) (forward-char 1))
  837.     (setq texinfo-command-end (point))
  838.     (nreverse args)))
  839.  
  840. (defun texinfo-format-parse-defun-args ()
  841.   (goto-char texinfo-command-end)
  842.   (let ((start (point)))
  843.     (end-of-line)
  844.     (setq texinfo-command-end (1+ (point)))
  845.     (let ((marker (move-marker (make-marker) texinfo-command-end)))
  846.       (texinfo-format-expand-region start (point))
  847.       (setq texinfo-command-end (marker-position marker))
  848.       (move-marker marker nil))
  849.     (goto-char start)
  850.     (let ((args '())
  851.           beg end)
  852.       (skip-chars-forward " ")
  853.       (while (not (eolp))
  854.         (cond ((looking-at "{")
  855.                (setq beg (1+ (point)))
  856.                (forward-list 1)
  857.                (setq end (1- (point))))
  858.               (t
  859.                (setq beg (point))
  860.                (re-search-forward "[\n ]")
  861.                (forward-char -1)
  862.                (setq end (point))))
  863.         (setq args (cons (buffer-substring beg end) args))
  864.         (skip-chars-forward " "))
  865.       (forward-char 1)
  866.       (nreverse args))))
  867.  
  868. (defun texinfo-discard-line ()
  869.   (goto-char texinfo-command-end)
  870.   (skip-chars-forward " \t")
  871.   (or (eolp)
  872.       (error "Extraneous text at end of command line."))
  873.   (goto-char texinfo-command-start)
  874.   (or (bolp)
  875.       (error "Extraneous text at beginning of command line."))
  876.   (delete-region (point) (progn (forward-line 1) (point))))
  877.  
  878. (defun texinfo-discard-line-with-args ()
  879.   (goto-char texinfo-command-start)
  880.   (delete-region (point) (progn (forward-line 1) (point))))
  881.  
  882.  
  883. ;;; @setfilename
  884.  
  885. ;; Only `texinfo-format-buffer' handles @setfilename with this
  886. ;; definition; `texinfo-format-region' handles @setfilename, if any,
  887. ;; specially. 
  888. (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
  889. (defun texinfo-format-setfilename ()
  890.   (let ((arg (texinfo-parse-arg-discard)))
  891.     (message "Formatting Info file: %s" arg)
  892.     (setq texinfo-format-filename
  893.           (file-name-nondirectory (expand-file-name arg)))
  894.     (insert "Info file: "
  895.             texinfo-format-filename ",    -*-Text-*-\n"
  896.             "produced by `texinfo-format-buffer'\n"
  897.             "from file"
  898.             (if (buffer-file-name input-buffer)
  899.                 (concat " `"
  900.                         (file-name-sans-versions
  901.                          (file-name-nondirectory
  902.                           (buffer-file-name input-buffer)))
  903.                         "'")
  904.               (concat "buffer `" (buffer-name input-buffer) "'"))
  905.             "\nusing `texinfmt.el' version "
  906.             texinfmt-version
  907.             ".\n\n")))
  908.  
  909. ;;; @node, @menu
  910.  
  911. (put 'node 'texinfo-format 'texinfo-format-node)
  912. (put 'nwnode 'texinfo-format 'texinfo-format-node)
  913. (defun texinfo-format-node ()
  914.   (let* ((args (texinfo-format-parse-line-args))
  915.          (name (nth 0 args))
  916.          (next (nth 1 args))
  917.          (prev (nth 2 args))
  918.          (up (nth 3 args)))
  919.     (texinfo-discard-command)
  920.     (setq texinfo-last-node name)
  921.     (let ((tem (downcase name)))
  922.       (if (assoc tem texinfo-node-names)
  923.           (error "Duplicate node name: %s" name)
  924.         (setq texinfo-node-names (cons (list tem) texinfo-node-names))))
  925.     (setq texinfo-footnote-number 0)
  926.     ;; insert "\n\^_" unconditionally since this is what info is looking for
  927.     (insert "\n\^_\nFile: " texinfo-format-filename
  928.             ", Node: " name)
  929.     (if next
  930.         (insert ", Next: " next))
  931.     (if prev
  932.         (insert ", Prev: " prev))
  933.     (if up
  934.         (insert ", Up: " up))
  935.     (insert ?\n)
  936.     (setq texinfo-last-node-pos (point))))
  937.  
  938. (put 'menu 'texinfo-format 'texinfo-format-menu)
  939. (defun texinfo-format-menu ()
  940.   (texinfo-discard-line)
  941.   (insert "* Menu:\n\n"))
  942.  
  943. (put 'menu 'texinfo-end 'texinfo-discard-command)
  944.  
  945.  
  946. ;;; Cross references
  947.  
  948. ; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
  949. ; -> *Note FNAME: (FILE)NODE
  950. ;   If FILE is missing,
  951. ;    *Note FNAME: NODE
  952. ;   If FNAME is empty and NAME is present
  953. ;    *Note NAME: Node
  954. ;   If both NAME and FNAME are missing
  955. ;    *Note NODE::
  956. ;   texinfo ignores the DOCUMENT argument.
  957. ; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
  958. ;   If FILE is specified, (FILE)NODE is used for xrefs.
  959. ;   If fifth argument DOCUMENT is specified, produces
  960. ;    See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
  961. ;    of DOCUMENT
  962.  
  963. ; @ref             a reference that does not put `See' or `see' in
  964. ;                  the hardcopy and is the same as @xref in Info
  965. (put 'ref 'texinfo-format 'texinfo-format-xref)
  966.  
  967. (put 'xref 'texinfo-format 'texinfo-format-xref)
  968. (defun texinfo-format-xref ()
  969.   (let ((args (texinfo-format-parse-args)))
  970.     (texinfo-discard-command)
  971.     (insert "*Note ")
  972.     (let ((fname (or (nth 1 args) (nth 2 args))))
  973.       (if (null (or fname (nth 3 args)))
  974.           (insert (car args) "::")
  975.         (insert (or fname (car args)) ": ")
  976.         (if (nth 3 args)
  977.             (insert "(" (nth 3 args) ")"))
  978.         (insert (car args))))))
  979.  
  980. (put 'pxref 'texinfo-format 'texinfo-format-pxref)
  981. (defun texinfo-format-pxref ()
  982.   (texinfo-format-xref)
  983.   (or (save-excursion
  984.         (forward-char -2)
  985.         (looking-at "::"))
  986.       (insert ".")))
  987.  
  988. ;@inforef{NODE, FNAME, FILE}
  989. ;Like @xref{NODE, FNAME,,FILE} in texinfo.
  990. ;In Tex, generates "See Info file FILE, node NODE"
  991. (put 'inforef 'texinfo-format 'texinfo-format-inforef)
  992. (defun texinfo-format-inforef ()
  993.   (let ((args (texinfo-format-parse-args)))
  994.     (texinfo-discard-command)
  995.     (if (nth 1 args)
  996.         (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
  997.       (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
  998.  
  999.  
  1000. ;;; Section headings
  1001.  
  1002. (put 'majorheading 'texinfo-format 'texinfo-format-chapter)
  1003. (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
  1004. (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
  1005. (put 'chapter 'texinfo-format 'texinfo-format-chapter)
  1006. (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
  1007. (put 'appendix 'texinfo-format 'texinfo-format-chapter)
  1008. (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
  1009. (put 'top 'texinfo-format 'texinfo-format-chapter)
  1010. (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
  1011. (defun texinfo-format-chapter ()
  1012.   (texinfo-format-chapter-1 ?*))
  1013.  
  1014. (put 'heading 'texinfo-format 'texinfo-format-section)
  1015. (put 'isection 'texinfo-format 'texinfo-format-section)
  1016. (put 'section 'texinfo-format 'texinfo-format-section)
  1017. (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
  1018. (put 'appendixsection 'texinfo-format 'texinfo-format-section)
  1019. (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
  1020. (put 'appendixsec 'texinfo-format 'texinfo-format-section)
  1021. (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
  1022. (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
  1023. (defun texinfo-format-section ()
  1024.   (texinfo-format-chapter-1 ?=))
  1025.  
  1026. (put 'subheading 'texinfo-format 'texinfo-format-subsection)
  1027. (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
  1028. (put 'subsection 'texinfo-format 'texinfo-format-subsection)
  1029. (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
  1030. (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
  1031. (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
  1032. (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
  1033. (defun texinfo-format-subsection ()
  1034.   (texinfo-format-chapter-1 ?-))
  1035.  
  1036. (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
  1037. (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
  1038. (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
  1039. (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  1040. (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  1041. (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  1042. (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  1043. (defun texinfo-format-subsubsection ()
  1044.   (texinfo-format-chapter-1 ?.))
  1045.  
  1046. (defun texinfo-format-chapter-1 (belowchar)
  1047.   (let ((arg (texinfo-parse-arg-discard)))
  1048.     (message "Formatting: %s ... " arg)   ; So we can see where we are.
  1049.     (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
  1050.     (forward-line -2)))
  1051.  
  1052. (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
  1053. (defun texinfo-format-sectionpad ()
  1054.   (let ((str (texinfo-parse-arg-discard)))
  1055.     (forward-char -1)
  1056.     (let ((column (current-column)))
  1057.       (forward-char 1)
  1058.       (while (> column 0)
  1059.         (insert str)
  1060.         (setq column (1- column))))
  1061.     (insert ?\n)))
  1062.  
  1063.  
  1064. ;;; Space controlling commands:  @. and @:, and the soft hyphen.
  1065.  
  1066. (put '\. 'texinfo-format 'texinfo-format-\.)
  1067. (defun texinfo-format-\. ()
  1068.   (texinfo-discard-command)
  1069.   (insert "."))
  1070.  
  1071. (put '\: 'texinfo-format 'texinfo-format-\:)
  1072. (defun texinfo-format-\: ()
  1073.   (texinfo-discard-command))
  1074.  
  1075. (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
  1076. (defun texinfo-format-soft-hyphen ()
  1077.   (texinfo-discard-command))
  1078.  
  1079.  
  1080. ;;; @center, @sp, and @br
  1081.  
  1082. (put 'center 'texinfo-format 'texinfo-format-center)
  1083. (defun texinfo-format-center ()
  1084.   (let ((arg (texinfo-parse-expanded-arg)))
  1085.     (texinfo-discard-command)
  1086.     (insert arg)
  1087.     (insert ?\n)
  1088.     (save-restriction
  1089.       (goto-char (1- (point)))
  1090.       (let ((indent-tabs-mode nil))
  1091.         (center-line)))))
  1092.  
  1093. (put 'sp 'texinfo-format 'texinfo-format-sp)
  1094. (defun texinfo-format-sp ()
  1095.   (let* ((arg (texinfo-parse-arg-discard))
  1096.          (num (read arg)))
  1097.     (insert-char ?\n num)))
  1098.  
  1099. (put 'br 'texinfo-format 'texinfo-format-paragraph-break)
  1100. (defun texinfo-format-paragraph-break ()
  1101.   "Force a paragraph break.
  1102. If used within a line, follow `@br' with braces."
  1103.   (texinfo-optional-braces-discard)
  1104.   ;; insert one return if at end of line;
  1105.   ;; else insert two returns, to generate a blank line.
  1106.   (if (= (following-char) ?\n)
  1107.       (insert ?\n)
  1108.     (insert-char ?\n 2)))
  1109.  
  1110.  
  1111. ;;; @footnote  and  @footnotestyle
  1112.  
  1113. ; In Texinfo, footnotes are created with the `@footnote' command.
  1114. ; This command is followed immediately by a left brace, then by the text of
  1115. ; the footnote, and then by a terminating right brace.  The
  1116. ; template for a footnote is:
  1117. ;      @footnote{TEXT}
  1118. ;
  1119. ; Info has two footnote styles:
  1120. ;    * In the End of node style, all the footnotes for a single node
  1121. ;      are placed at the end of that node.  The footnotes are
  1122. ;      separated from the rest of the node by a line of dashes with
  1123. ;      the word `Footnotes' within it.
  1124. ;    * In the Separate node style, all the footnotes for a single node
  1125. ;      are placed in an automatically constructed node of their own.
  1126.  
  1127. ; Footnote style is specified by the @footnotestyle command, either
  1128. ;    @footnotestyle separate
  1129. ; or
  1130. ;    @footnotestyle end
  1131. ; The default is  separate
  1132.  
  1133. (defvar texinfo-footnote-style "separate" 
  1134.   "Footnote style, either separate or end.")
  1135.  
  1136. (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle)
  1137. (defun texinfo-footnotestyle ()
  1138.   "Specify whether footnotes are at end of node or in separate nodes.
  1139. Argument is either end or separate."
  1140.   (setq texinfo-footnote-style (texinfo-parse-arg-discard)))
  1141.  
  1142. (defvar texinfo-footnote-number)
  1143.  
  1144. (put 'footnote 'texinfo-format 'texinfo-format-footnote)
  1145. (defun texinfo-format-footnote ()
  1146.   "Format a footnote in either end of node or separate node style.
  1147. The   texinfo-footnote-style  variable controls which style is used."
  1148.   (setq texinfo-footnote-number (1+ texinfo-footnote-number))
  1149.   (cond ((string= texinfo-footnote-style "end")
  1150.          (texinfo-format-end-node))
  1151.         ((string= texinfo-footnote-style "separate")
  1152.          (texinfo-format-separate-node))))
  1153.  
  1154. (defun texinfo-format-separate-node ()
  1155.   "Format footnote in Separate node style, with notes in own node.
  1156. The node is constructed automatically."
  1157.   (let* (start
  1158.          (arg (texinfo-parse-line-arg))
  1159.          (node-name-beginning
  1160.           (save-excursion
  1161.             (re-search-backward
  1162.              "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
  1163.             (match-end 0)))
  1164.          (node-name
  1165.           (save-excursion
  1166.             (buffer-substring
  1167.              (progn (goto-char node-name-beginning) ; skip over node command
  1168.                     (skip-chars-forward " \t")  ; and over spaces
  1169.                     (point))
  1170.              (if (search-forward
  1171.                   ","
  1172.                   (save-excursion (end-of-line) (point)) t) ; bound search
  1173.                  (1- (point))
  1174.                (end-of-line) (point))))))
  1175.     (texinfo-discard-command)  ; remove or insert whitespace, as needed
  1176.     (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
  1177.                    (point))
  1178.     (insert (format " (%d) (*Note %s-Footnotes::)"
  1179.                     texinfo-footnote-number node-name))
  1180.     (fill-paragraph nil)
  1181.     (save-excursion
  1182.     (if (re-search-forward "^@node" nil 'move)
  1183.         (forward-line -1))
  1184.  
  1185.     ;; two cases: for the first footnote, we must insert a node header;
  1186.     ;; for the second and subsequent footnotes, we need only insert 
  1187.     ;; the text of the  footnote.
  1188.  
  1189.     (if (save-excursion
  1190.          (re-search-backward
  1191.           (concat node-name "-Footnotes, Up: ")
  1192.           node-name-beginning
  1193.           t))
  1194.         (progn   ; already at least one footnote
  1195.           (setq start (point))
  1196.           (insert (format "\n(%d)  %s\n" texinfo-footnote-number arg))
  1197.           (fill-region start (point)))
  1198.       ;; else not yet a footnote
  1199.       (insert "\n\^_\nFile: "  texinfo-format-filename
  1200.               "  Node: " node-name "-Footnotes, Up: " node-name "\n")
  1201.       (setq start (point))
  1202.       (insert (format "\n(%d)  %s\n" texinfo-footnote-number arg))
  1203.       (fill-region start (point))))))
  1204.  
  1205. (defun texinfo-format-end-node ()
  1206.   "Format footnote in the End of node style, with notes at end of node."
  1207.   (let (start
  1208.         (arg (texinfo-parse-line-arg)))
  1209.     (texinfo-discard-command)  ; remove or insert whitespace, as needed
  1210.     (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
  1211.                    (point))
  1212.     (insert (format " (%d) " texinfo-footnote-number))
  1213.     (fill-paragraph nil)
  1214.     (save-excursion
  1215.       (if (search-forward "\n--------- Footnotes ---------\n" nil t)
  1216.           (progn ; already have footnote, put new one before end of node
  1217.             (if (re-search-forward "^@node" nil 'move)
  1218.                 (forward-line -1))
  1219.             (setq start (point))
  1220.             (insert (format "\n(%d)  %s\n" texinfo-footnote-number arg))
  1221.             (fill-region start (point)))
  1222.         ;; else no prior footnote
  1223.         (if (re-search-forward "^@node" nil 'move)
  1224.             (forward-line -1))
  1225.         (insert "\n--------- Footnotes ---------\n")
  1226.         (setq start (point))
  1227.         (insert (format "\n(%d)  %s\n" texinfo-footnote-number arg))))))
  1228.  
  1229.  
  1230. ;;; @itemize, @enumerate, and similar commands
  1231.  
  1232. ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
  1233. ;; @enumerate pushes (enumerate 0 STARTPOS).
  1234. ;; @item dispatches to the texinfo-item prop of the first elt of the list.
  1235. ;; For itemize, this puts in and rescans the COMMANDS.
  1236. ;; For enumerate, this increments the number and puts it in.
  1237. ;; In either case, it puts a Backspace at the front of the line
  1238. ;; which marks it not to be indented later.
  1239. ;; All other lines get indented by 5 when the @end is reached.
  1240.  
  1241. (defvar texinfo-stack-depth 0
  1242.   "Count of number of unpopped texinfo-push-stack calls.
  1243. Used by @refill indenting command to avoid indenting within lists, etc.")
  1244.  
  1245. (defun texinfo-push-stack (check arg)
  1246.   (setq texinfo-stack-depth (1+ texinfo-stack-depth))
  1247.   (setq texinfo-stack
  1248.         (cons (list check arg texinfo-command-start)
  1249.               texinfo-stack)))
  1250.  
  1251. (defun texinfo-pop-stack (check)
  1252.   (setq texinfo-stack-depth (1- texinfo-stack-depth))
  1253.   (if (null texinfo-stack)
  1254.       (error "Unmatched @end %s" check))
  1255.   (if (not (eq (car (car texinfo-stack)) check))
  1256.       (error "@end %s matches @%s"
  1257.              check (car (car texinfo-stack))))
  1258.   (prog1 (cdr (car texinfo-stack))
  1259.          (setq texinfo-stack (cdr texinfo-stack))))
  1260.  
  1261. (put 'itemize 'texinfo-format 'texinfo-itemize)
  1262. (defun texinfo-itemize ()
  1263.   (texinfo-push-stack
  1264.    'itemize
  1265.    (progn (skip-chars-forward " \t")
  1266.           (if (eolp)
  1267.               "@bullet"
  1268.             (texinfo-parse-line-arg))))
  1269.   (texinfo-discard-line-with-args)
  1270.   (setq fill-column (- fill-column 5)))
  1271.  
  1272. (put 'itemize 'texinfo-end 'texinfo-end-itemize)
  1273. (defun texinfo-end-itemize ()
  1274.   (setq fill-column (+ fill-column 5))
  1275.   (texinfo-discard-command)
  1276.   (let ((stacktop
  1277.          (texinfo-pop-stack 'itemize)))
  1278.     (texinfo-do-itemize (nth 1 stacktop))))
  1279.  
  1280. (put 'enumerate 'texinfo-format 'texinfo-enumerate)
  1281. (defun texinfo-enumerate ()
  1282.   (texinfo-push-stack
  1283.    'enumerate 
  1284.    (progn (skip-chars-forward " \t")
  1285.           (if (eolp)
  1286.               1
  1287.             (read (current-buffer)))))
  1288.   (if (and (symbolp (car (cdr (car texinfo-stack))))
  1289.            (> 1 (length (symbol-name (car (cdr (car texinfo-stack)))))))
  1290.       (error
  1291.        "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." ))
  1292.   (texinfo-discard-line-with-args)
  1293.   (setq fill-column (- fill-column 5)))
  1294.  
  1295. (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
  1296. (defun texinfo-end-enumerate ()
  1297.   (setq fill-column (+ fill-column 5))
  1298.   (texinfo-discard-command)
  1299.   (let ((stacktop
  1300.          (texinfo-pop-stack 'enumerate)))
  1301.     (texinfo-do-itemize (nth 1 stacktop))))
  1302.  
  1303. ;; @alphaenumerate never became a standard part of Texinfo
  1304. (put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate)
  1305. (defun texinfo-alphaenumerate ()
  1306.   (texinfo-push-stack 'alphaenumerate (1- ?a))
  1307.   (setq fill-column (- fill-column 5))
  1308.   (texinfo-discard-line))
  1309.  
  1310. (put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate)
  1311. (defun texinfo-end-alphaenumerate ()
  1312.   (setq fill-column (+ fill-column 5))
  1313.   (texinfo-discard-command)
  1314.   (let ((stacktop
  1315.          (texinfo-pop-stack 'alphaenumerate)))
  1316.     (texinfo-do-itemize (nth 1 stacktop))))
  1317.  
  1318. ;; @capsenumerate never became a standard part of Texinfo
  1319. (put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate)
  1320. (defun texinfo-capsenumerate ()
  1321.   (texinfo-push-stack 'capsenumerate (1- ?A))
  1322.   (setq fill-column (- fill-column 5))
  1323.   (texinfo-discard-line))
  1324.  
  1325. (put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate)
  1326. (defun texinfo-end-capsenumerate ()
  1327.   (setq fill-column (+ fill-column 5))
  1328.   (texinfo-discard-command)
  1329.   (let ((stacktop
  1330.          (texinfo-pop-stack 'capsenumerate)))
  1331.     (texinfo-do-itemize (nth 1 stacktop))))
  1332.  
  1333. ;; At the @end, indent all the lines within the construct
  1334. ;; except those marked with backspace.  FROM says where
  1335. ;; construct started.
  1336. (defun texinfo-do-itemize (from)
  1337.   (save-excursion
  1338.    (while (progn (forward-line -1)
  1339.                  (>= (point) from))
  1340.      (if (= (following-char) ?\b)
  1341.          (save-excursion
  1342.            (delete-char 1)
  1343.            (end-of-line)
  1344.            (delete-char 6))
  1345.        (if (not (looking-at "[ \t]*$"))
  1346.            (save-excursion (insert "     ")))))))
  1347.  
  1348. (put 'item 'texinfo-format 'texinfo-item)
  1349. (put 'itemx 'texinfo-format 'texinfo-item)
  1350. (defun texinfo-item ()
  1351.   (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
  1352.  
  1353. (put 'itemize 'texinfo-item 'texinfo-itemize-item)
  1354. (defun texinfo-itemize-item ()
  1355.   ;; (texinfo-discard-line)   ; Did not handle text on same line as @item.
  1356.   (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point)))
  1357.   (if (looking-at "[ \t]*[^ \t\n]+")
  1358.       ;; Text on same line as @item command.
  1359.       (insert "\b   " (nth 1 (car texinfo-stack)) " \n")
  1360.     ;; Else text on next line.
  1361.     (insert "\b   " (nth 1 (car texinfo-stack)) " "))
  1362.   (forward-line -1))
  1363.  
  1364. (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
  1365. (defun texinfo-enumerate-item ()
  1366.   (texinfo-discard-line)
  1367.   (let (enumerating-symbol)
  1368.     (cond ((integerp (car (cdr (car texinfo-stack))))
  1369.            (setq enumerating-symbol (car (cdr (car texinfo-stack))))
  1370.            (insert ?\b (format "%3d. " enumerating-symbol) ?\n)
  1371.            (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol)))
  1372.           ((symbolp (car (cdr (car texinfo-stack))))
  1373.            (setq enumerating-symbol
  1374.                  (symbol-name (car (cdr (car texinfo-stack)))))
  1375.            (if (or (equal ?\[ (string-to-char enumerating-symbol))
  1376.                    (equal ?\{ (string-to-char enumerating-symbol)))
  1377.                (error
  1378.                 "Too many items in enumerated list; alphabet ends at Z."))
  1379.            (insert ?\b (format "%3s. " enumerating-symbol) ?\n)
  1380.            (setcar (cdr (car texinfo-stack))
  1381.                    (make-symbol
  1382.                     (char-to-string
  1383.                      (1+ 
  1384.                       (string-to-char enumerating-symbol))))))
  1385.           (t
  1386.           (error
  1387.            "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." )))
  1388.     (forward-line -1)))
  1389.  
  1390. (put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item)
  1391. (defun texinfo-alphaenumerate-item ()
  1392.   (texinfo-discard-line)
  1393.   (let ((next (1+ (car (cdr (car texinfo-stack))))))
  1394.     (if (> next ?z)
  1395.         (error "More than 26 items in @alphaenumerate; get a bigger alphabet."))
  1396.     (setcar (cdr (car texinfo-stack)) next)
  1397.     (insert "\b  " next ". \n"))
  1398.   (forward-line -1))
  1399.  
  1400. (put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item)
  1401. (defun texinfo-capsenumerate-item ()
  1402.   (texinfo-discard-line)
  1403.   (let ((next (1+ (car (cdr (car texinfo-stack))))))
  1404.     (if (> next ?Z)
  1405.         (error "More than 26 items in @capsenumerate; get a bigger alphabet."))
  1406.     (setcar (cdr (car texinfo-stack)) next)
  1407.     (insert "\b  " next ". \n"))
  1408.   (forward-line -1))
  1409.  
  1410.  
  1411. ;;; @table
  1412.  
  1413. ; The `@table' command produces two-column tables.
  1414.  
  1415. (put 'table 'texinfo-format 'texinfo-table)
  1416. (defun texinfo-table ()
  1417.   (texinfo-push-stack 
  1418.    'table 
  1419.    (progn (skip-chars-forward " \t")
  1420.           (if (eolp)
  1421.               "@asis"
  1422.             (texinfo-parse-line-arg))))
  1423.   (texinfo-discard-line-with-args)
  1424.   (setq fill-column (- fill-column 5)))
  1425.  
  1426. (put 'table 'texinfo-item 'texinfo-table-item)
  1427. (defun texinfo-table-item ()
  1428.   (let ((arg (texinfo-parse-arg-discard))
  1429.         (itemfont (car (cdr (car texinfo-stack)))))
  1430.     (insert ?\b itemfont ?\{ arg "}\n     \n"))
  1431.   (forward-line -2))
  1432.  
  1433. (put 'table 'texinfo-end 'texinfo-end-table)
  1434. (defun texinfo-end-table ()
  1435.   (setq fill-column (+ fill-column 5))
  1436.   (texinfo-discard-command)
  1437.   (let ((stacktop
  1438.          (texinfo-pop-stack 'table)))
  1439.     (texinfo-do-itemize (nth 1 stacktop))))
  1440.  
  1441. ;; @description appears to be an undocumented variant on @table that
  1442. ;; does not require an arg.  It fails in texinfo.tex 2.58 and is not
  1443. ;; part of makeinfo.c   The command appears to be a relic of the past.
  1444. (put 'description 'texinfo-end 'texinfo-end-table)
  1445. (put 'description 'texinfo-format 'texinfo-description)
  1446. (defun texinfo-description ()
  1447.   (texinfo-push-stack 'table "@asis")
  1448.   (setq fill-column (- fill-column 5))
  1449.   (texinfo-discard-line))
  1450.  
  1451.  
  1452. ;;; @ftable, @vtable
  1453.  
  1454. ; The `@ftable' and `@vtable' commands are like the `@table' command
  1455. ; but they also insert each entry in the first column of the table
  1456. ; into the function or variable index.
  1457.  
  1458. ;; Handle the @ftable and @vtable commands:
  1459.  
  1460. (put 'ftable 'texinfo-format 'texinfo-ftable)
  1461. (put 'vtable 'texinfo-format 'texinfo-vtable)
  1462.  
  1463. (defun texinfo-ftable () (texinfo-indextable 'ftable))
  1464. (defun texinfo-vtable () (texinfo-indextable 'vtable))
  1465.  
  1466. (defun texinfo-indextable (table-type)
  1467.   (texinfo-push-stack table-type (texinfo-parse-arg-discard))
  1468.   (setq fill-column (- fill-column 5)))
  1469.  
  1470. ;; Handle the @item commands within ftable and vtable:
  1471.  
  1472. (put 'ftable 'texinfo-item 'texinfo-ftable-item)
  1473. (put 'vtable 'texinfo-item 'texinfo-vtable-item)
  1474.  
  1475. (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex))
  1476. (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex))
  1477.  
  1478. (defun texinfo-indextable-item (index-type)
  1479.   (let ((item (texinfo-parse-arg-discard))
  1480.         (itemfont (car (cdr (car texinfo-stack))))
  1481.         (indexvar index-type))
  1482.     (insert ?\b itemfont ?\{ item "}\n     \n")
  1483.     (set indexvar
  1484.          (cons
  1485.           (list item texinfo-last-node)
  1486.           (symbol-value indexvar)))
  1487.     (forward-line -2)))
  1488.  
  1489. ;; Handle @end ftable, @end vtable
  1490.  
  1491. (put 'ftable 'texinfo-end 'texinfo-end-ftable)
  1492. (put 'vtable 'texinfo-end 'texinfo-end-vtable)
  1493.  
  1494. (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable))
  1495. (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable))
  1496.  
  1497. (defun texinfo-end-indextable (table-type)
  1498.   (setq fill-column (+ fill-column 5))
  1499.   (texinfo-discard-command)
  1500.   (let ((stacktop
  1501.          (texinfo-pop-stack table-type)))
  1502.     (texinfo-do-itemize (nth 1 stacktop))))
  1503.  
  1504.  
  1505. ;;; @ifinfo,  @iftex, @tex, @ifhtml, @html
  1506.  
  1507. (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
  1508. (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
  1509.  
  1510. (put 'iftex 'texinfo-format 'texinfo-format-iftex)
  1511. (defun texinfo-format-iftex ()
  1512.   (delete-region texinfo-command-start
  1513.                  (progn (re-search-forward "@end iftex[ \t]*\n")
  1514.                         (point))))
  1515.  
  1516. (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
  1517. (defun texinfo-format-ifhtml ()
  1518.   (delete-region texinfo-command-start
  1519.                  (progn (re-search-forward "@end ifhtml[ \t]*\n")
  1520.                         (point))))
  1521.  
  1522. (put 'tex 'texinfo-format 'texinfo-format-tex)
  1523. (defun texinfo-format-tex ()
  1524.   (delete-region texinfo-command-start
  1525.                  (progn (re-search-forward "@end tex[ \t]*\n")
  1526.                         (point))))
  1527.  
  1528. (put 'html 'texinfo-format 'texinfo-format-html)
  1529. (defun texinfo-format-html ()
  1530.   (delete-region texinfo-command-start
  1531.                  (progn (re-search-forward "@end html[ \t]*\n")
  1532.                         (point))))
  1533.  
  1534.  
  1535. ;;; @titlepage
  1536.  
  1537. (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
  1538. (defun texinfo-format-titlepage ()
  1539.   (delete-region texinfo-command-start
  1540.                  (progn (re-search-forward "@end titlepage[ \t]*\n")
  1541.                         (point))))
  1542.  
  1543. (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
  1544.  
  1545. ; @titlespec         an alternative titling command; ignored by Info
  1546.  
  1547. (put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
  1548. (defun texinfo-format-titlespec ()
  1549.   (delete-region texinfo-command-start
  1550.                  (progn (re-search-forward "@end titlespec[ \t]*\n")
  1551.                         (point))))
  1552.  
  1553. (put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
  1554.  
  1555.  
  1556. ;;; @today
  1557.  
  1558. (put 'today 'texinfo-format 'texinfo-format-today)
  1559.  
  1560. ; Produces Day Month Year style of output.  eg `1 Jan 1900'
  1561. ; The `@today{}' command requires a pair of braces, like `@dots{}'.
  1562. (defun texinfo-format-today ()
  1563.   (texinfo-parse-arg-discard)
  1564.   (insert (format-time-string "%e %b %Y")))
  1565.  
  1566.  
  1567. ;;; @ignore
  1568.  
  1569. (put 'ignore 'texinfo-format 'texinfo-format-ignore)
  1570. (defun texinfo-format-ignore ()
  1571.   (delete-region texinfo-command-start
  1572.                  (progn (re-search-forward "@end ignore[ \t]*\n")
  1573.                         (point))))
  1574.  
  1575. (put 'endignore 'texinfo-format 'texinfo-discard-line)
  1576.  
  1577.  
  1578. ;;; Define the Info enclosure command: @definfoenclose
  1579.  
  1580. ; A `@definfoenclose' command may be used to define a highlighting
  1581. ; command for Info, but not for TeX.  A command defined using
  1582. ; `@definfoenclose' marks text by enclosing it in strings that precede
  1583. ; and follow the text.
  1584. ; Presumably, if you define a command with `@definfoenclose` for Info,
  1585. ; you will also define the same command in the TeX definitions file,
  1586. ; `texinfo.tex' in a manner appropriate for typesetting.
  1587. ; Write a `@definfoenclose' command on a line and follow it with three
  1588. ; arguments separated by commas (commas are used as separators in an
  1589. ; `@node' line in the same way).  The first argument to
  1590. ; `@definfoenclose' is the @-command name \(without the `@'\); the
  1591. ; second argument is the Info start delimiter string; and the third
  1592. ; argument is the Info end delimiter string.  The latter two arguments
  1593. ; enclose the highlighted text in the Info file.  A delimiter string
  1594. ; may contain spaces.  Neither the start nor end delimiter is
  1595. ; required.  However, if you do not provide a start delimiter, you
  1596. ; must follow the command name with two commas in a row; otherwise,
  1597. ; the Info formatting commands will misinterpret the end delimiter
  1598. ; string as a start delimiter string.
  1599. ;
  1600. ; If you do a @definfoenclose{} on the name of a pre-defined macro (such
  1601. ; as @emph{}, @strong{}, @tt{}, or @i{}) the enclosure definition will
  1602. ; override the built-in definition.
  1603. ; An enclosure command defined this way takes one argument in braces.
  1604. ;
  1605. ; For example, you can write:
  1606. ;
  1607. ;     @ifinfo
  1608. ;     @definfoenclose phoo, //, \\
  1609. ;     @end ifinfo
  1610. ;
  1611. ; near the beginning of a Texinfo file at the beginning of the lines
  1612. ; to define `@phoo' as an Info formatting command that inserts `//'
  1613. ; before and `\\' after the argument to `@phoo'.  You can then write
  1614. ; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info.
  1615. ;
  1616. ; Also, for TeX formatting, you could write 
  1617. ;
  1618. ;     @iftex
  1619. ;     @global@let@phoo=@i
  1620. ;     @end iftex
  1621. ;
  1622. ; to define `@phoo' as a command that causes TeX to typeset
  1623. ; the argument to `@phoo' in italics.
  1624. ;
  1625. ; Note that each definition applies to its own formatter: one for TeX,
  1626. ; the other for texinfo-format-buffer or texinfo-format-region.
  1627. ;
  1628. ; Here is another example: write
  1629. ;
  1630. ;     @definfoenclose headword, , :
  1631. ;
  1632. ; near the beginning of the file, to define `@headword' as an Info
  1633. ; formatting command that inserts nothing before and a colon after the
  1634. ; argument to `@headword'.
  1635.  
  1636. (put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure)
  1637. (defun texinfo-define-info-enclosure ()
  1638.   (let* ((args (texinfo-format-parse-line-args))
  1639.          (command-name (nth 0 args))
  1640.          (beginning-delimiter (or (nth 1 args) ""))
  1641.          (end-delimiter (or (nth 2 args) "")))
  1642.     (texinfo-discard-command)
  1643.     (setq texinfo-enclosure-list
  1644.         (cons
  1645.          (list command-name
  1646.                (list
  1647.                 beginning-delimiter
  1648.                 end-delimiter))
  1649.          texinfo-enclosure-list))))
  1650.  
  1651.  
  1652. ;;; @var, @code and the like
  1653.  
  1654. (put 'var 'texinfo-format 'texinfo-format-var)
  1655. ;  @sc  a small caps font for TeX; formatted as `var' in Info
  1656. (put 'sc 'texinfo-format 'texinfo-format-var)
  1657. (defun texinfo-format-var ()
  1658.   (insert (upcase (texinfo-parse-arg-discard)))
  1659.   (goto-char texinfo-command-start))
  1660.  
  1661. ; various noops
  1662.  
  1663. (put 'b 'texinfo-format 'texinfo-format-noop)
  1664. (put 'i 'texinfo-format 'texinfo-format-noop)
  1665. (put 'r 'texinfo-format 'texinfo-format-noop)
  1666. (put 't 'texinfo-format 'texinfo-format-noop)
  1667. (put 'w 'texinfo-format 'texinfo-format-noop)
  1668. (put 'asis 'texinfo-format 'texinfo-format-noop)
  1669. (put 'dmn 'texinfo-format 'texinfo-format-noop)
  1670. (put 'key 'texinfo-format 'texinfo-format-noop)
  1671. (put 'math 'texinfo-format 'texinfo-format-noop)
  1672. (put 'titlefont 'texinfo-format 'texinfo-format-noop)
  1673. (defun texinfo-format-noop ()
  1674.   (insert (texinfo-parse-arg-discard))
  1675.   (goto-char texinfo-command-start))
  1676.  
  1677. (put 'cite 'texinfo-format 'texinfo-format-code)
  1678. (put 'code 'texinfo-format 'texinfo-format-code)
  1679. (put 'file 'texinfo-format 'texinfo-format-code)
  1680. (put 'kbd 'texinfo-format 'texinfo-format-code)
  1681. (put 'samp 'texinfo-format 'texinfo-format-code)
  1682. (defun texinfo-format-code ()
  1683.   (insert "`" (texinfo-parse-arg-discard) "'")
  1684.   (goto-char texinfo-command-start))
  1685.  
  1686. (put 'emph 'texinfo-format 'texinfo-format-emph)
  1687. (put 'strong 'texinfo-format 'texinfo-format-emph)
  1688. (defun texinfo-format-emph ()
  1689.   (insert "*" (texinfo-parse-arg-discard) "*")
  1690.   (goto-char texinfo-command-start))
  1691.  
  1692. (put 'dfn 'texinfo-format 'texinfo-format-defn)
  1693. (put 'defn 'texinfo-format 'texinfo-format-defn)
  1694. (defun texinfo-format-defn ()
  1695.   (insert "\"" (texinfo-parse-arg-discard) "\"")
  1696.   (goto-char texinfo-command-start))
  1697.  
  1698. (put 'bullet 'texinfo-format 'texinfo-format-bullet)
  1699. (defun texinfo-format-bullet ()
  1700.   "Insert an asterisk.
  1701. If used within a line, follow `@bullet' with braces."
  1702.   (texinfo-optional-braces-discard)
  1703.   (insert "*"))
  1704.  
  1705.  
  1706. ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample
  1707.  
  1708. (put 'display 'texinfo-format 'texinfo-format-example)
  1709. (put 'example 'texinfo-format 'texinfo-format-example)
  1710. (put 'lisp 'texinfo-format 'texinfo-format-example)
  1711. (put 'quotation 'texinfo-format 'texinfo-format-example)
  1712. (put 'smallexample 'texinfo-format 'texinfo-format-example)
  1713. (put 'smalllisp 'texinfo-format 'texinfo-format-example)
  1714. (defun texinfo-format-example ()
  1715.   (texinfo-push-stack 'example nil)
  1716.   (setq fill-column (- fill-column 5))
  1717.   (texinfo-discard-line))
  1718.  
  1719. (put 'example 'texinfo-end 'texinfo-end-example)
  1720. (put 'display 'texinfo-end 'texinfo-end-example)
  1721. (put 'lisp 'texinfo-end 'texinfo-end-example)
  1722. (put 'quotation 'texinfo-end 'texinfo-end-example)
  1723. (put 'smallexample 'texinfo-end 'texinfo-end-example)
  1724. (put 'smalllisp 'texinfo-end 'texinfo-end-example)
  1725. (defun texinfo-end-example ()
  1726.   (setq fill-column (+ fill-column 5))
  1727.   (texinfo-discard-command)
  1728.   (let ((stacktop
  1729.          (texinfo-pop-stack 'example)))
  1730.     (texinfo-do-itemize (nth 1 stacktop))))
  1731.  
  1732. (put 'exdent 'texinfo-format 'texinfo-format-exdent)
  1733. (defun texinfo-format-exdent ()
  1734.   (texinfo-discard-command)
  1735.   (delete-region (point)
  1736.                  (progn
  1737.                   (skip-chars-forward " ")
  1738.                   (point)))
  1739.   (insert ?\b)
  1740.   ;; Cancel out the deletion that texinfo-do-itemize
  1741.   ;; is going to do at the end of this line.
  1742.   (save-excursion
  1743.     (end-of-line)
  1744.     (insert "\n     ")))
  1745.  
  1746.  
  1747. ;;; @cartouche 
  1748.  
  1749. ; The @cartouche command is a noop in Info; in a printed manual,
  1750. ; it makes a box with rounded corners.
  1751.  
  1752. (put 'cartouche 'texinfo-format 'texinfo-discard-line)
  1753. (put 'cartouche 'texinfo-end 'texinfo-discard-command)
  1754.  
  1755.  
  1756. ;;; @flushleft and @format
  1757.  
  1758. ; The @flushleft command left justifies every line but leaves the
  1759. ; right end ragged.  As far as Info is concerned, @flushleft is a
  1760. ; `do-nothing' command
  1761.  
  1762. ; The @format command is similar to @example except that it does not
  1763. ; indent; this means that in Info, @format is similar to @flushleft.
  1764.  
  1765. (put 'format 'texinfo-format 'texinfo-format-flushleft)
  1766. (put 'flushleft 'texinfo-format 'texinfo-format-flushleft)
  1767. (defun texinfo-format-flushleft ()
  1768.   (texinfo-discard-line))
  1769.  
  1770. (put 'format 'texinfo-end 'texinfo-end-flushleft)
  1771. (put 'flushleft 'texinfo-end 'texinfo-end-flushleft)
  1772. (defun texinfo-end-flushleft ()
  1773.   (texinfo-discard-command))
  1774.  
  1775.  
  1776. ;;; @flushright
  1777.  
  1778. ; The @flushright command right justifies every line but leaves the
  1779. ; left end ragged.  Spaces and tabs at the right ends of lines are
  1780. ; removed so that visible text lines up on the right side.
  1781.  
  1782. (put 'flushright 'texinfo-format 'texinfo-format-flushright)
  1783. (defun texinfo-format-flushright ()
  1784.   (texinfo-push-stack 'flushright nil)
  1785.   (texinfo-discard-line))
  1786.  
  1787. (put 'flushright 'texinfo-end 'texinfo-end-flushright)
  1788. (defun texinfo-end-flushright ()
  1789.   (texinfo-discard-command)
  1790.  
  1791.   (let ((stacktop
  1792.          (texinfo-pop-stack 'flushright)))
  1793.  
  1794.     (texinfo-do-flushright (nth 1 stacktop))))
  1795.  
  1796. (defun texinfo-do-flushright (from)
  1797.   (save-excursion
  1798.    (while (progn (forward-line -1)
  1799.                  (>= (point) from))
  1800.  
  1801.      (beginning-of-line)
  1802.      (insert
  1803.       (make-string
  1804.        (- fill-column
  1805.           (save-excursion
  1806.             (end-of-line) 
  1807.             (skip-chars-backward " \t")
  1808.             (delete-region (point) (progn (end-of-line) (point)))
  1809.             (current-column)))  
  1810.        ? )))))
  1811.  
  1812.  
  1813. ;;; @ctrl, @TeX, @copyright, @minus, @dots
  1814.  
  1815. (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
  1816. (defun texinfo-format-ctrl ()
  1817.   (let ((str (texinfo-parse-arg-discard)))
  1818.     (insert (logand 31 (aref str 0)))))
  1819.  
  1820. (put 'TeX 'texinfo-format 'texinfo-format-TeX)
  1821. (defun texinfo-format-TeX ()
  1822.   (texinfo-parse-arg-discard)
  1823.   (insert "TeX"))
  1824.  
  1825. (put 'copyright 'texinfo-format 'texinfo-format-copyright)
  1826. (defun texinfo-format-copyright ()
  1827.   (texinfo-parse-arg-discard)
  1828.   (insert "(C)"))
  1829.  
  1830. (put 'minus 'texinfo-format 'texinfo-format-minus)
  1831. (defun texinfo-format-minus ()
  1832.   "Insert a minus sign.
  1833. If used within a line, follow `@minus' with braces."
  1834.   (texinfo-optional-braces-discard)
  1835.   (insert "-"))
  1836.  
  1837. (put 'dots 'texinfo-format 'texinfo-format-dots)
  1838. (defun texinfo-format-dots ()
  1839.   (texinfo-parse-arg-discard)
  1840.   (insert "..."))
  1841.  
  1842. (put 'enddots 'texinfo-format 'texinfo-format-enddots)
  1843. (defun texinfo-format-enddots ()
  1844.   (texinfo-parse-arg-discard)
  1845.   (insert "...."))
  1846.  
  1847.  
  1848. ;;; Refilling and indenting:  @refill, @paragraphindent, @noindent
  1849.  
  1850. ;;; Indent only those paragraphs that are refilled as a result of an
  1851. ;;; @refill command.  
  1852.  
  1853. ;    * If the value is `asis', do not change the existing indentation at
  1854. ;      the starts of paragraphs.
  1855.  
  1856. ;    * If the value zero, delete any existing indentation.
  1857.  
  1858. ;    * If the value is greater than zero, indent each paragraph by that
  1859. ;      number of spaces.
  1860.  
  1861. ;;; But do not refill paragraphs with an @refill command that are
  1862. ;;; preceded by @noindent or are part of a table, list, or deffn.
  1863.  
  1864. (defvar texinfo-paragraph-indent "asis"
  1865.   "Number of spaces for @refill to indent a paragraph; else to leave as is.")
  1866.  
  1867. (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent)
  1868.  
  1869. (defun texinfo-paragraphindent ()
  1870.   "Specify the number of spaces for @refill to indent a paragraph.
  1871. Default is to leave the number of spaces as is."
  1872.   (let ((arg  (texinfo-parse-arg-discard)))
  1873.     (if (string= "asis" arg)
  1874.         (setq texinfo-paragraph-indent "asis")
  1875.       (setq texinfo-paragraph-indent (string-to-int arg)))))
  1876.  
  1877. (put 'refill 'texinfo-format 'texinfo-format-refill)
  1878. (defun texinfo-format-refill ()
  1879.   "Refill paragraph. Also, indent first line as set by @paragraphindent.
  1880. Default is to leave paragraph indentation as is."
  1881.   (texinfo-discard-command)
  1882.   (forward-paragraph -1)     
  1883.   (if (looking-at "[ \t\n]*$") (forward-line 1))
  1884.   ;; Do not indent if an entry in a list, table, or deffn,
  1885.   ;; or if paragraph is preceded by @noindent.
  1886.   ;; Otherwise, indent
  1887.   (cond 
  1888.    ;; delete a @noindent line and do not indent paragraph
  1889.    ((save-excursion (forward-line -1)
  1890.                     (looking-at "^@noindent")) 
  1891.     (forward-line -1)
  1892.     (delete-region (point) (progn (forward-line 1) (point))))
  1893.    ;; do nothing if "asis"
  1894.    ((equal texinfo-paragraph-indent "asis"))
  1895.    ;; do no indenting in list, etc.
  1896.    ((> texinfo-stack-depth 0))   
  1897.    ;; otherwise delete existing whitespace and indent
  1898.    (t 
  1899.     (delete-region (point) (progn (skip-chars-forward " \t") (point)))
  1900.     (insert (make-string texinfo-paragraph-indent ? ))))
  1901.   (forward-paragraph 1) 
  1902.   (forward-line -1)
  1903.   (end-of-line)
  1904.   ;; Do not fill a section title line with asterisks, hyphens, etc. that
  1905.   ;; are used to underline it.  This could occur if the line following
  1906.   ;; the underlining is not an index entry and has text within it.
  1907.   ;; XEmacs change: the standard 3.6 paragraph separators cause
  1908.   ;; texinfmt to fail on vm.texi so we continue to use the older version.
  1909.   (let* ((previous-paragraph-separate paragraph-separate)
  1910.          (paragraph-separate (concat paragraph-separate "\\|^[=*---.]+"))
  1911.          (previous-paragraph-start paragraph-start)
  1912.          (paragraph-start (concat paragraph-start "\\|^[=*---.]+")))
  1913.     (unwind-protect
  1914.         (fill-paragraph nil)
  1915.       (setq paragraph-separate previous-paragraph-separate)
  1916.       (setq paragraph-start previous-paragraph-start))))
  1917.  
  1918. (put 'noindent 'texinfo-format 'texinfo-noindent)
  1919. (defun texinfo-noindent ()  
  1920.   (save-excursion 
  1921.     (forward-paragraph 1)
  1922.     (if (search-backward "@refill"
  1923.                             (save-excursion (forward-line -1) (point)) t)
  1924.         () ; leave @noindent command so @refill command knows not to indent
  1925.       ;; else
  1926.       (texinfo-discard-line))))
  1927.  
  1928.  
  1929. ;;; Index generation
  1930.  
  1931. (put 'vindex 'texinfo-format 'texinfo-format-vindex)
  1932. (defun texinfo-format-vindex ()
  1933.   (texinfo-index 'texinfo-vindex))
  1934.  
  1935. (put 'cindex 'texinfo-format 'texinfo-format-cindex)
  1936. (defun texinfo-format-cindex ()
  1937.   (texinfo-index 'texinfo-cindex))
  1938.  
  1939. (put 'findex 'texinfo-format 'texinfo-format-findex)
  1940. (defun texinfo-format-findex ()
  1941.   (texinfo-index 'texinfo-findex))
  1942.  
  1943. (put 'pindex 'texinfo-format 'texinfo-format-pindex)
  1944. (defun texinfo-format-pindex ()
  1945.   (texinfo-index 'texinfo-pindex))
  1946.  
  1947. (put 'tindex 'texinfo-format 'texinfo-format-tindex)
  1948. (defun texinfo-format-tindex ()
  1949.   (texinfo-index 'texinfo-tindex))
  1950.  
  1951. (put 'kindex 'texinfo-format 'texinfo-format-kindex)
  1952. (defun texinfo-format-kindex ()
  1953.   (texinfo-index 'texinfo-kindex))
  1954.  
  1955. (defun texinfo-index (indexvar)
  1956.   (let ((arg (texinfo-parse-expanded-arg)))
  1957.     (texinfo-discard-command)
  1958.     (set indexvar
  1959.          (cons (list arg
  1960.                      texinfo-last-node
  1961.                      ;; Region formatting may not provide last node position.
  1962.                      (if texinfo-last-node-pos
  1963.                          (1+ (count-lines texinfo-last-node-pos (point)))
  1964.                        1))
  1965.                (symbol-value indexvar)))))
  1966.  
  1967. (defconst texinfo-indexvar-alist
  1968.   '(("cp" . texinfo-cindex)
  1969.     ("fn" . texinfo-findex)
  1970.     ("vr" . texinfo-vindex)
  1971.     ("tp" . texinfo-tindex)
  1972.     ("pg" . texinfo-pindex)
  1973.     ("ky" . texinfo-kindex)))
  1974.  
  1975.  
  1976. ;;; @defindex   @defcodeindex
  1977. (put 'defindex 'texinfo-format 'texinfo-format-defindex)
  1978. (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
  1979.  
  1980. (defun texinfo-format-defindex ()
  1981.   (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
  1982.          (indexing-command (intern (concat index-name "index")))
  1983.          (index-formatting-command      ; eg: `texinfo-format-aaindex'
  1984.           (intern (concat "texinfo-format-" index-name "index")))
  1985.          (index-alist-name              ; eg: `texinfo-aaindex'
  1986.           (intern (concat "texinfo-" index-name "index"))))
  1987.  
  1988.     (set index-alist-name nil)
  1989.  
  1990.     (put indexing-command               ; eg, aaindex
  1991.          'texinfo-format
  1992.          index-formatting-command)      ; eg, texinfo-format-aaindex
  1993.  
  1994.     ;; eg: "aa" . texinfo-aaindex
  1995.     (or (assoc index-name texinfo-indexvar-alist)
  1996.         (setq texinfo-indexvar-alist
  1997.               (cons
  1998.                (cons index-name
  1999.                      index-alist-name)
  2000.                texinfo-indexvar-alist)))
  2001.  
  2002.     (fset index-formatting-command
  2003.           (list 'lambda 'nil
  2004.                 (list 'texinfo-index 
  2005.                       (list 'quote index-alist-name))))))
  2006.  
  2007.  
  2008. ;;; @synindex   @syncodeindex
  2009.  
  2010. (put 'synindex 'texinfo-format 'texinfo-format-synindex)
  2011. (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
  2012.  
  2013. (defun texinfo-format-synindex ()
  2014.   (let* ((args (texinfo-parse-arg-discard))
  2015.          (second (cdr (read-from-string args)))
  2016.          (joiner (symbol-name (car (read-from-string args))))
  2017.          (joined (symbol-name (car (read-from-string args second)))))
  2018.  
  2019.     (if (assoc joiner texinfo-short-index-cmds-alist)
  2020.         (put
  2021.           (cdr (assoc joiner texinfo-short-index-cmds-alist))
  2022.          'texinfo-format
  2023.          (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
  2024.              (intern (concat "texinfo-format-" joined "index"))))
  2025.       (put
  2026.        (intern (concat joiner "index"))
  2027.        'texinfo-format
  2028.        (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
  2029.            (intern (concat "texinfo-format-" joined "index")))))))
  2030.  
  2031. (defconst texinfo-short-index-cmds-alist
  2032.   '(("cp" . cindex)
  2033.     ("fn" . findex)
  2034.     ("vr" . vindex)
  2035.     ("tp" . tindex)
  2036.     ("pg" . pindex)
  2037.     ("ky" . kindex)))
  2038.  
  2039. (defconst texinfo-short-index-format-cmds-alist
  2040.   '(("cp" . texinfo-format-cindex)
  2041.     ("fn" . texinfo-format-findex)
  2042.     ("vr" . texinfo-format-vindex)
  2043.     ("tp" . texinfo-format-tindex)
  2044.     ("pg" . texinfo-format-pindex)
  2045.     ("ky" . texinfo-format-kindex)))
  2046.  
  2047.  
  2048. ;;; Sort and index (for VMS)
  2049.  
  2050. ;; Sort an index which is in the current buffer between START and END.
  2051. ;; Used on VMS, where the `sort' utility is not available.
  2052. (defun texinfo-sort-region (start end)
  2053.   (require 'sort)
  2054.   (save-restriction
  2055.     (narrow-to-region start end)
  2056.     (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun)))
  2057.  
  2058. ;; Subroutine for sorting an index.
  2059. ;; At start of a line, return a string to sort the line under.
  2060. (defun texinfo-sort-startkeyfun ()
  2061.   (let ((line
  2062.          (buffer-substring (point) (save-excursion (end-of-line) (point)))))
  2063.     ;; Canonicalize whitespace and eliminate funny chars.
  2064.     (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
  2065.       (setq line (concat (substring line 0 (match-beginning 0))
  2066.                          " "
  2067.                          (substring line (match-end 0) (length line)))))
  2068.     line))
  2069.  
  2070.  
  2071. ;;; @printindex
  2072.  
  2073. (put 'printindex 'texinfo-format 'texinfo-format-printindex)
  2074.  
  2075. (defun texinfo-format-printindex ()
  2076.   (let ((indexelts (symbol-value
  2077.                     (cdr (assoc (texinfo-parse-arg-discard)
  2078.                                 texinfo-indexvar-alist))))
  2079.         opoint)
  2080.     (insert "\n* Menu:\n\n")
  2081.     (setq opoint (point))
  2082.     (texinfo-print-index nil indexelts)
  2083.  
  2084.     (if (eq system-type 'vax-vms)
  2085.         (texinfo-sort-region opoint (point))
  2086.       (shell-command-on-region opoint (point) "sort -fd" 1))))
  2087.  
  2088. (defun texinfo-print-index (file indexelts)
  2089.   (while indexelts
  2090.     (if (stringp (car (car indexelts)))
  2091.         (progn
  2092.           (insert "* " (car (car indexelts)) ": " )
  2093.           (indent-to 32)
  2094.           (insert
  2095.            (if file (concat "(" file ")") "")
  2096.            (nth 1 (car indexelts)) ".")
  2097.           (indent-to 54)
  2098.           (insert
  2099.            (if (nth 2 (car indexelts))
  2100.                (format "  %d." (nth 2 (car indexelts)))
  2101.              "")
  2102.            "\n"))
  2103.       ;; index entries from @include'd file
  2104.       (texinfo-print-index (nth 1 (car indexelts))
  2105.                            (nth 2 (car indexelts))))
  2106.     (setq indexelts (cdr indexelts))))
  2107.  
  2108.  
  2109. ;;; Glyphs: @equiv, @error, etc
  2110.  
  2111. ;; @equiv           to show that two expressions are equivalent
  2112. ;; @error           to show an error message
  2113. ;; @expansion       to show what a macro expands to
  2114. ;; @point           to show the location of point in an example
  2115. ;; @print           to show what an evaluated expression prints
  2116. ;; @result          to indicate the value returned by an expression
  2117.  
  2118. (put 'equiv 'texinfo-format 'texinfo-format-equiv)
  2119. (defun texinfo-format-equiv ()
  2120.   (texinfo-parse-arg-discard)
  2121.   (insert "=="))
  2122.  
  2123. (put 'error 'texinfo-format 'texinfo-format-error)
  2124. (defun texinfo-format-error ()
  2125.   (texinfo-parse-arg-discard)
  2126.   (insert "error-->"))
  2127.  
  2128. (put 'expansion 'texinfo-format 'texinfo-format-expansion)
  2129. (defun texinfo-format-expansion ()
  2130.   (texinfo-parse-arg-discard)
  2131.   (insert "==>"))
  2132.  
  2133. (put 'point 'texinfo-format 'texinfo-format-point)
  2134. (defun texinfo-format-point ()
  2135.   (texinfo-parse-arg-discard)
  2136.   (insert "-!-"))
  2137.  
  2138. (put 'print 'texinfo-format 'texinfo-format-print)
  2139. (defun texinfo-format-print ()
  2140.   (texinfo-parse-arg-discard)
  2141.   (insert "-|"))
  2142.  
  2143. (put 'result 'texinfo-format 'texinfo-format-result)
  2144. (defun texinfo-format-result ()
  2145.   (texinfo-parse-arg-discard)
  2146.   (insert "=>"))
  2147.  
  2148.  
  2149. ;;; Definition formatting: @deffn, @defun, etc
  2150.  
  2151. ;; What definition formatting produces:
  2152. ;;
  2153. ;; @deffn category name args...
  2154. ;;     In Info, `Category: name ARGS'
  2155. ;;     In index: name:  node. line#.
  2156. ;;
  2157. ;; @defvr category name 
  2158. ;;     In Info, `Category: name'
  2159. ;;     In index: name:  node. line#.
  2160. ;;
  2161. ;; @deftp category name attributes...
  2162. ;; `category name attributes...'       Note: @deftp args in lower case.
  2163. ;;     In index: name:  node. line#.
  2164. ;;
  2165. ;; Specialized function-like or variable-like entity:
  2166. ;;
  2167. ;; @defun, @defmac, @defspec, @defvar, @defopt
  2168. ;;
  2169. ;; @defun name args           In Info, `Function: name ARGS'
  2170. ;; @defmac name args          In Info, `Macro: name ARGS'
  2171. ;; @defvar name               In Info, `Variable: name'
  2172. ;; etc.
  2173. ;;     In index: name:  node. line#.
  2174. ;;
  2175. ;; Generalized typed-function-like or typed-variable-like entity:
  2176. ;; @deftypefn category data-type name args...
  2177. ;;     In Info, `Category:  data-type name args...'
  2178. ;; @deftypevr category data-type name 
  2179. ;;     In Info, `Category:  data-type name'
  2180. ;;     In index: name:  node. line#.
  2181. ;;
  2182. ;; Specialized typed-function-like or typed-variable-like entity:
  2183. ;; @deftypefun data-type name args...
  2184. ;;     In Info, `Function:  data-type name ARGS'
  2185. ;;     In index: name:  node. line#.   
  2186. ;;
  2187. ;; @deftypevar data-type name 
  2188. ;;     In Info, `Variable:  data-type name'
  2189. ;;     In index: name:  node. line#.   but include args after name!?
  2190. ;;
  2191. ;; Generalized object oriented entity: 
  2192. ;; @defop category class name args...
  2193. ;;     In Info, `Category on class: name ARG'
  2194. ;;     In index: name on class: node. line#.
  2195. ;;
  2196. ;; @defcv category class name         
  2197. ;;     In Info, `Category of class: name'
  2198. ;;     In index: name of class: node. line#.
  2199. ;;
  2200. ;; Specialized object oriented entity:
  2201. ;; @defmethod class name args... 
  2202. ;;     In Info, `Method on class: name ARGS'
  2203. ;;     In index: name on class: node. line#.
  2204. ;;
  2205. ;; @defivar class name
  2206. ;;     In Info, `Instance variable of class: name'
  2207. ;;     In index: name of class: node. line#.
  2208.  
  2209.  
  2210. ;;; The definition formatting functions
  2211.  
  2212. (defun texinfo-format-defun ()
  2213.   (texinfo-push-stack 'defun nil)
  2214.   (setq fill-column (- fill-column 5))
  2215.   (texinfo-format-defun-1 t))
  2216.  
  2217. (defun texinfo-end-defun ()
  2218.   (setq fill-column (+ fill-column 5))
  2219.   (texinfo-discard-command)
  2220.   (let ((start (nth 1 (texinfo-pop-stack 'defun))))
  2221.     (texinfo-do-itemize start)
  2222.     ;; Delete extra newline inserted after header.
  2223.     (save-excursion
  2224.       (goto-char start)
  2225.       (delete-char -1))))
  2226.  
  2227. (defun texinfo-format-defunx ()
  2228.   (texinfo-format-defun-1 nil))
  2229.  
  2230. (defun texinfo-format-defun-1 (first-p)
  2231.   (let ((parse-args (texinfo-format-parse-defun-args))
  2232.         (texinfo-defun-type (get texinfo-command-name 'texinfo-defun-type)))
  2233.     (texinfo-discard-command)
  2234.     ;; Delete extra newline inserted after previous header line.
  2235.     (if (not first-p)
  2236.         (delete-char -1))
  2237.     (funcall
  2238.      (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args)
  2239.     ;; Insert extra newline so that paragraph filling does not mess
  2240.     ;; with header line.
  2241.     (insert "\n\n")
  2242.     (rplaca (cdr (cdr (car texinfo-stack))) (point))
  2243.     (funcall
  2244.      (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args)))
  2245.  
  2246. ;;; Formatting the first line of a definition
  2247.  
  2248. ;; @deffn, @defvr, @deftp
  2249. (put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  2250. (put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  2251. (put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  2252. (put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  2253. (put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  2254. (put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  2255. (defun texinfo-format-deffn (parsed-args)
  2256.   ;; Generalized function-like, variable-like, or generic data-type entity:
  2257.   ;; @deffn category name args...
  2258.   ;;     In Info, `Category: name ARGS'
  2259.   ;; @deftp category name attributes...
  2260.   ;; `category name attributes...'       Note: @deftp args in lower case.
  2261.   (let ((category (car parsed-args))
  2262.         (name (car (cdr parsed-args)))
  2263.         (args (cdr (cdr parsed-args))))
  2264.     (insert " -- " category ": " name)
  2265.     (while args
  2266.       (insert " "
  2267.               (if (or (= ?& (aref (car args) 0))
  2268.                       (eq (eval (car texinfo-defun-type)) 'deftp-type))
  2269.                   (car args)
  2270.                 (upcase (car args))))
  2271.       (setq args (cdr args)))))
  2272.  
  2273. ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple
  2274. (put 'defun 'texinfo-deffn-formatting-property
  2275.      'texinfo-format-specialized-defun)
  2276. (put 'defunx 'texinfo-deffn-formatting-property
  2277.      'texinfo-format-specialized-defun)
  2278. (put 'defmac 'texinfo-deffn-formatting-property
  2279.      'texinfo-format-specialized-defun)
  2280. (put 'defmacx 'texinfo-deffn-formatting-property
  2281.      'texinfo-format-specialized-defun)
  2282. (put 'defspec 'texinfo-deffn-formatting-property
  2283.      'texinfo-format-specialized-defun)
  2284. (put 'defspecx 'texinfo-deffn-formatting-property
  2285.      'texinfo-format-specialized-defun)
  2286. (put 'defvar 'texinfo-deffn-formatting-property
  2287.      'texinfo-format-specialized-defun)
  2288. (put 'defvarx 'texinfo-deffn-formatting-property
  2289.      'texinfo-format-specialized-defun)
  2290. (put 'defopt 'texinfo-deffn-formatting-property
  2291.      'texinfo-format-specialized-defun)
  2292. (put 'defoptx 'texinfo-deffn-formatting-property
  2293.      'texinfo-format-specialized-defun)
  2294. (defun texinfo-format-specialized-defun (parsed-args)
  2295.   ;; Specialized function-like or variable-like entity:
  2296.   ;; @defun name args           In Info, `Function: Name ARGS'
  2297.   ;; @defmac name args          In Info, `Macro: Name ARGS'
  2298.   ;; @defvar name               In Info, `Variable: Name'
  2299.   ;; Use cdr of texinfo-defun-type to determine category:
  2300.   (let ((category (car (cdr texinfo-defun-type)))
  2301.         (name (car parsed-args))
  2302.         (args (cdr parsed-args)))
  2303.     (insert " -- " category ": " name)
  2304.     (while args
  2305.       (insert " "
  2306.               (if (= ?& (aref (car args) 0))
  2307.                   (car args)
  2308.                 (upcase (car args))))
  2309.       (setq args (cdr args)))))
  2310.  
  2311. ;; @deftypefn, @deftypevr: Generalized typed
  2312. (put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  2313. (put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  2314. (put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  2315. (put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  2316. (defun texinfo-format-deftypefn (parsed-args)
  2317.   ;; Generalized typed-function-like or typed-variable-like entity:
  2318.   ;; @deftypefn category data-type name args...
  2319.   ;;     In Info, `Category:  data-type name args...'
  2320.   ;; @deftypevr category data-type name 
  2321.   ;;     In Info, `Category:  data-type name'
  2322.   ;; Note: args in lower case, unless modified in command line.
  2323.   (let ((category (car parsed-args))
  2324.         (data-type (car (cdr parsed-args)))
  2325.         (name (car (cdr (cdr parsed-args))))
  2326.         (args (cdr (cdr (cdr parsed-args)))))
  2327.     (insert " -- " category ": " data-type " " name)
  2328.     (while args
  2329.       (insert " " (car args))
  2330.       (setq args (cdr args)))))
  2331.  
  2332. ;; @deftypefun, @deftypevar: Specialized typed
  2333. (put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
  2334. (put 'deftypefunx 'texinfo-deffn-formatting-property
  2335.      'texinfo-format-deftypefun)
  2336. (put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
  2337. (put 'deftypevarx 'texinfo-deffn-formatting-property
  2338.      'texinfo-format-deftypefun)
  2339. (defun texinfo-format-deftypefun (parsed-args)
  2340.   ;; Specialized typed-function-like or typed-variable-like entity:
  2341.   ;; @deftypefun data-type name args...
  2342.   ;;     In Info, `Function:  data-type name ARGS'
  2343.   ;; @deftypevar data-type name 
  2344.   ;;     In Info, `Variable:  data-type name'
  2345.   ;; Note: args in lower case, unless modified in command line.
  2346.   ;; Use cdr of texinfo-defun-type to determine category:
  2347.   (let ((category (car (cdr texinfo-defun-type)))
  2348.         (data-type (car parsed-args))
  2349.         (name (car (cdr  parsed-args)))
  2350.         (args (cdr (cdr parsed-args))))
  2351.     (insert " -- " category ": " data-type " " name)
  2352.     (while args
  2353.       (insert " " (car args))
  2354.       (setq args (cdr args)))))
  2355.  
  2356. ;; @defop: Generalized object-oriented
  2357. (put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop)
  2358. (put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop)
  2359. (defun texinfo-format-defop (parsed-args)
  2360.   ;; Generalized object oriented entity: 
  2361.   ;; @defop category class name args...
  2362.   ;;     In Info, `Category on class: name ARG'
  2363.   ;; Note: args in upper case; use of `on'
  2364.   (let ((category (car parsed-args))
  2365.         (class (car (cdr parsed-args)))
  2366.         (name (car (cdr (cdr parsed-args))))
  2367.         (args (cdr (cdr (cdr parsed-args)))))
  2368.     (insert " -- " category " on " class ": " name)
  2369.     (while args
  2370.       (insert " " (upcase (car args)))
  2371.       (setq args (cdr args)))))
  2372.  
  2373. ;; @defcv: Generalized object-oriented
  2374. (put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
  2375. (put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
  2376. (defun texinfo-format-defcv (parsed-args)
  2377.   ;; Generalized object oriented entity: 
  2378.   ;; @defcv category class name         
  2379.   ;;     In Info, `Category of class: name'
  2380.   ;; Note: args in upper case; use of `of'
  2381.   (let ((category (car parsed-args))
  2382.         (class (car (cdr parsed-args)))
  2383.         (name (car (cdr (cdr parsed-args))))
  2384.         (args (cdr (cdr (cdr parsed-args)))))
  2385.     (insert " -- " category " of " class ": " name)
  2386.     (while args
  2387.       (insert " " (upcase (car args)))
  2388.       (setq args (cdr args)))))
  2389.  
  2390. ;; @defmethod: Specialized object-oriented
  2391. (put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
  2392. (put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
  2393. (defun texinfo-format-defmethod (parsed-args)
  2394.   ;; Specialized object oriented entity:
  2395.   ;; @defmethod class name args... 
  2396.   ;;     In Info, `Method on class: name ARGS'
  2397.   ;; Note: args in upper case; use of `on'
  2398.   ;; Use cdr of texinfo-defun-type to determine category:
  2399.   (let ((category (car (cdr texinfo-defun-type)))
  2400.         (class (car parsed-args))
  2401.         (name (car (cdr  parsed-args)))
  2402.         (args (cdr  (cdr parsed-args))))
  2403.     (insert " -- " category " on " class ": " name)
  2404.     (while args
  2405.       (insert " " (upcase (car args)))
  2406.       (setq args (cdr args)))))
  2407.  
  2408. ;; @defivar: Specialized object-oriented
  2409. (put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
  2410. (put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
  2411. (defun texinfo-format-defivar (parsed-args)
  2412.   ;; Specialized object oriented entity:
  2413.   ;; @defivar class name
  2414.   ;;     In Info, `Instance variable of class: name'
  2415.   ;; Note: args in upper case; use of `of'
  2416.   ;; Use cdr of texinfo-defun-type to determine category:
  2417.   (let ((category (car (cdr texinfo-defun-type)))
  2418.         (class (car parsed-args))
  2419.         (name (car (cdr  parsed-args)))
  2420.         (args (cdr  (cdr parsed-args))))
  2421.     (insert " -- " category " of " class ": " name)
  2422.     (while args
  2423.       (insert " " (upcase (car args)))
  2424.       (setq args (cdr args)))))
  2425.  
  2426.  
  2427. ;;; Indexing for definitions
  2428.  
  2429. ;; An index entry has three parts: the `entry proper', the node name, and the
  2430. ;; line number.  Depending on the which command is used, the entry is
  2431. ;; formatted differently:
  2432. ;;
  2433. ;; @defun, 
  2434. ;; @defmac, 
  2435. ;; @defspec, 
  2436. ;; @defvar, 
  2437. ;; @defopt          all use their 1st argument as the entry-proper 
  2438. ;;
  2439. ;; @deffn, 
  2440. ;; @defvr, 
  2441. ;; @deftp 
  2442. ;; @deftypefun
  2443. ;; @deftypevar      all use their 2nd argument as the entry-proper
  2444. ;;
  2445. ;; @deftypefn, 
  2446. ;; @deftypevr       both use their 3rd argument as the entry-proper  
  2447. ;;
  2448. ;; @defmethod       uses its 2nd and 1st arguments as an entry-proper 
  2449. ;;                    formatted: NAME on CLASS
  2450.  
  2451. ;; @defop           uses its 3rd and 2nd arguments as an entry-proper 
  2452. ;;                    formatted: NAME on CLASS
  2453. ;;        
  2454. ;; @defivar         uses its 2nd and 1st arguments as an entry-proper
  2455. ;;                    formatted: NAME of CLASS
  2456. ;;
  2457. ;; @defcv           uses its 3rd and 2nd argument as an entry-proper
  2458. ;;                    formatted: NAME of CLASS
  2459.  
  2460. (put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2461. (put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2462. (put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2463. (put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2464. (put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2465. (put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2466. (put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2467. (put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  2468. (put 'defopt  'texinfo-defun-indexing-property 'texinfo-index-defun)
  2469. (put 'defoptx  'texinfo-defun-indexing-property 'texinfo-index-defun)
  2470. (defun texinfo-index-defun (parsed-args)
  2471.   ;; use 1st parsed-arg  as entry-proper
  2472.   ;; `index-list' will be texinfo-findex or the like
  2473.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2474.     (set index-list
  2475.          (cons 
  2476.           ;; Three elements: entry-proper, node-name, line-number
  2477.           (list
  2478.            (car parsed-args)
  2479.            texinfo-last-node
  2480.            ;; Region formatting may not provide last node position.
  2481.            (if texinfo-last-node-pos
  2482.                (1+ (count-lines texinfo-last-node-pos (point)))
  2483.              1))
  2484.           (symbol-value index-list)))))
  2485.  
  2486. (put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2487. (put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2488. (put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2489. (put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2490. (put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2491. (put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2492. (put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2493. (put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2494. (put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2495. (put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  2496. (defun texinfo-index-deffn (parsed-args) 
  2497.  ;; use 2nd parsed-arg  as entry-proper
  2498.   ;; `index-list' will be texinfo-findex or the like
  2499.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2500.     (set index-list
  2501.          (cons 
  2502.           ;; Three elements: entry-proper, node-name, line-number
  2503.           (list
  2504.            (car (cdr parsed-args))
  2505.            texinfo-last-node
  2506.            ;; Region formatting may not provide last node position.
  2507.            (if texinfo-last-node-pos
  2508.                (1+ (count-lines texinfo-last-node-pos (point)))
  2509.              1))
  2510.           (symbol-value index-list)))))
  2511.  
  2512. (put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  2513. (put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  2514. (put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  2515. (put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  2516. (defun texinfo-index-deftypefn (parsed-args)
  2517.   ;; use 3rd parsed-arg  as entry-proper
  2518.   ;; `index-list' will be texinfo-findex or the like
  2519.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2520.     (set index-list
  2521.          (cons 
  2522.           ;; Three elements: entry-proper, node-name, line-number
  2523.           (list
  2524.            (car (cdr (cdr parsed-args)))
  2525.            texinfo-last-node
  2526.            ;; Region formatting may not provide last node position.
  2527.            (if texinfo-last-node-pos
  2528.                (1+ (count-lines texinfo-last-node-pos (point)))
  2529.              1))
  2530.           (symbol-value index-list)))))
  2531.  
  2532. (put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
  2533. (put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
  2534. (defun texinfo-index-defmethod (parsed-args)
  2535.   ;; use 2nd on 1st parsed-arg  as entry-proper
  2536.   ;; `index-list' will be texinfo-findex or the like
  2537.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2538.     (set index-list
  2539.          (cons 
  2540.           ;; Three elements: entry-proper, node-name, line-number
  2541.           (list
  2542.            (format "%s on %s"            
  2543.                    (car (cdr parsed-args))
  2544.                    (car parsed-args))
  2545.            texinfo-last-node
  2546.            ;; Region formatting may not provide last node position.
  2547.            (if texinfo-last-node-pos
  2548.                (1+ (count-lines texinfo-last-node-pos (point)))
  2549.              1))
  2550.           (symbol-value index-list)))))
  2551.  
  2552. (put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop)
  2553. (put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop)
  2554. (defun texinfo-index-defop (parsed-args)
  2555.   ;; use 3rd on 2nd parsed-arg  as entry-proper
  2556.   ;; `index-list' will be texinfo-findex or the like
  2557.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2558.     (set index-list
  2559.          (cons 
  2560.           ;; Three elements: entry-proper, node-name, line-number
  2561.           (list
  2562.            (format "%s on %s"            
  2563.                    (car (cdr (cdr parsed-args)))
  2564.                    (car (cdr parsed-args)))
  2565.            texinfo-last-node
  2566.            ;; Region formatting may not provide last node position.
  2567.            (if texinfo-last-node-pos
  2568.                (1+ (count-lines texinfo-last-node-pos (point)))
  2569.              1))
  2570.           (symbol-value index-list)))))
  2571.  
  2572. (put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar)
  2573. (put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar)
  2574. (defun texinfo-index-defivar (parsed-args)
  2575.   ;; use 2nd of 1st parsed-arg  as entry-proper
  2576.   ;; `index-list' will be texinfo-findex or the like
  2577.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2578.     (set index-list
  2579.          (cons 
  2580.           ;; Three elements: entry-proper, node-name, line-number
  2581.           (list
  2582.            (format "%s of %s"            
  2583.                    (car (cdr parsed-args))
  2584.                    (car parsed-args))
  2585.            texinfo-last-node
  2586.            ;; Region formatting may not provide last node position.
  2587.            (if texinfo-last-node-pos
  2588.                (1+ (count-lines texinfo-last-node-pos (point)))
  2589.              1))
  2590.           (symbol-value index-list)))))
  2591.  
  2592. (put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv)
  2593. (put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv)
  2594. (defun texinfo-index-defcv (parsed-args)
  2595.   ;; use 3rd of 2nd parsed-arg  as entry-proper
  2596.   ;; `index-list' will be texinfo-findex or the like
  2597.   (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  2598.     (set index-list
  2599.          (cons 
  2600.           ;; Three elements: entry-proper, node-name, line-number
  2601.           (list
  2602.            (format "%s of %s"            
  2603.                    (car (cdr (cdr parsed-args)))
  2604.                    (car (cdr parsed-args)))
  2605.            texinfo-last-node
  2606.            ;; Region formatting may not provide last node position.
  2607.            (if texinfo-last-node-pos
  2608.                (1+ (count-lines texinfo-last-node-pos (point)))
  2609.              1))
  2610.           (symbol-value index-list)))))
  2611.  
  2612.  
  2613. ;;; Properties for definitions
  2614.  
  2615. ;; Each definition command has six properties:
  2616. ;;
  2617. ;; 1. texinfo-deffn-formatting-property      to format definition line
  2618. ;; 2. texinfo-defun-indexing-property        to create index entry
  2619. ;; 3. texinfo-format                         formatting command
  2620. ;; 4. texinfo-end                            end formatting command
  2621. ;; 5. texinfo-defun-type                     type of deffn to format
  2622. ;; 6. texinfo-defun-index                    type of index to use
  2623. ;;
  2624. ;; The `x' forms of each definition command are used for the second
  2625. ;; and subsequent header lines.
  2626.  
  2627. ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property
  2628. ;; are listed just before the appropriate formatting and indexing commands.
  2629.  
  2630. (put 'deffn 'texinfo-format 'texinfo-format-defun)
  2631. (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
  2632. (put 'deffn 'texinfo-end 'texinfo-end-defun)
  2633. (put 'deffn 'texinfo-defun-type '('deffn-type nil))
  2634. (put 'deffnx 'texinfo-defun-type '('deffn-type nil))
  2635. (put 'deffn 'texinfo-defun-index 'texinfo-findex)
  2636. (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
  2637.  
  2638. (put 'defun 'texinfo-format 'texinfo-format-defun)
  2639. (put 'defunx 'texinfo-format 'texinfo-format-defunx)
  2640. (put 'defun 'texinfo-end 'texinfo-end-defun)
  2641. (put 'defun 'texinfo-defun-type '('defun-type "Function"))
  2642. (put 'defunx 'texinfo-defun-type '('defun-type "Function"))
  2643. (put 'defun 'texinfo-defun-index 'texinfo-findex)
  2644. (put 'defunx 'texinfo-defun-index 'texinfo-findex)
  2645.  
  2646. (put 'defmac 'texinfo-format 'texinfo-format-defun)
  2647. (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
  2648. (put 'defmac 'texinfo-end 'texinfo-end-defun)
  2649. (put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
  2650. (put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
  2651. (put 'defmac 'texinfo-defun-index 'texinfo-findex)
  2652. (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
  2653.  
  2654. (put 'defspec 'texinfo-format 'texinfo-format-defun)
  2655. (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
  2656. (put 'defspec 'texinfo-end 'texinfo-end-defun)
  2657. (put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
  2658. (put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
  2659. (put 'defspec 'texinfo-defun-index 'texinfo-findex)
  2660. (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
  2661.  
  2662. (put 'defvr 'texinfo-format 'texinfo-format-defun)
  2663. (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
  2664. (put 'defvr 'texinfo-end 'texinfo-end-defun)
  2665. (put 'defvr 'texinfo-defun-type '('deffn-type nil))
  2666. (put 'defvrx 'texinfo-defun-type '('deffn-type nil))
  2667. (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
  2668. (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
  2669.  
  2670. (put 'defvar 'texinfo-format 'texinfo-format-defun)
  2671. (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
  2672. (put 'defvar 'texinfo-end 'texinfo-end-defun)
  2673. (put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
  2674. (put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
  2675. (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
  2676. (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
  2677.  
  2678. (put 'defconst 'texinfo-format 'texinfo-format-defun)
  2679. (put 'defconstx 'texinfo-format 'texinfo-format-defunx)
  2680. (put 'defconst 'texinfo-end 'texinfo-end-defun)
  2681. (put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
  2682. (put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
  2683. (put 'defconst 'texinfo-defun-index 'texinfo-vindex)
  2684. (put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
  2685.  
  2686. (put 'defcmd 'texinfo-format 'texinfo-format-defun)
  2687. (put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
  2688. (put 'defcmd 'texinfo-end 'texinfo-end-defun)
  2689. (put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
  2690. (put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
  2691. (put 'defcmd 'texinfo-defun-index 'texinfo-findex)
  2692. (put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
  2693.  
  2694. (put 'defopt 'texinfo-format 'texinfo-format-defun)
  2695. (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
  2696. (put 'defopt 'texinfo-end 'texinfo-end-defun)
  2697. (put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
  2698. (put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
  2699. (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
  2700. (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
  2701.  
  2702. (put 'deftp 'texinfo-format 'texinfo-format-defun)
  2703. (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
  2704. (put 'deftp 'texinfo-end 'texinfo-end-defun)
  2705. (put 'deftp 'texinfo-defun-type '('deftp-type nil))
  2706. (put 'deftpx 'texinfo-defun-type '('deftp-type nil))
  2707. (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
  2708. (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
  2709.  
  2710. ;;; Object-oriented stuff is a little hairier.
  2711.  
  2712. (put 'defop 'texinfo-format 'texinfo-format-defun)
  2713. (put 'defopx 'texinfo-format 'texinfo-format-defunx)
  2714. (put 'defop 'texinfo-end 'texinfo-end-defun)
  2715. (put 'defop 'texinfo-defun-type '('defop-type nil))
  2716. (put 'defopx 'texinfo-defun-type '('defop-type nil))
  2717. (put 'defop 'texinfo-defun-index 'texinfo-findex)
  2718. (put 'defopx 'texinfo-defun-index 'texinfo-findex)
  2719.  
  2720. (put 'defmethod 'texinfo-format 'texinfo-format-defun)
  2721. (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
  2722. (put 'defmethod 'texinfo-end 'texinfo-end-defun)
  2723. (put 'defmethod 'texinfo-defun-type '('defmethod-type "Method"))
  2724. (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method"))
  2725. (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
  2726. (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
  2727.  
  2728. (put 'defcv 'texinfo-format 'texinfo-format-defun)
  2729. (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
  2730. (put 'defcv 'texinfo-end 'texinfo-end-defun)
  2731. (put 'defcv 'texinfo-defun-type '('defop-type nil))
  2732. (put 'defcvx 'texinfo-defun-type '('defop-type nil))
  2733. (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
  2734. (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
  2735.  
  2736. (put 'defivar 'texinfo-format 'texinfo-format-defun)
  2737. (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
  2738. (put 'defivar 'texinfo-end 'texinfo-end-defun)
  2739. (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
  2740. (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
  2741. (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
  2742. (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
  2743.  
  2744. ;;; Typed functions and variables
  2745.  
  2746. (put 'deftypefn 'texinfo-format 'texinfo-format-defun)
  2747. (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx)
  2748. (put 'deftypefn 'texinfo-end 'texinfo-end-defun)
  2749. (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil))
  2750. (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil))
  2751. (put 'deftypefn 'texinfo-defun-index 'texinfo-findex)
  2752. (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex)
  2753.  
  2754. (put 'deftypefun 'texinfo-format 'texinfo-format-defun)
  2755. (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx)
  2756. (put 'deftypefun 'texinfo-end 'texinfo-end-defun)
  2757. (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function"))
  2758. (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function"))
  2759. (put 'deftypefun 'texinfo-defun-index 'texinfo-findex)
  2760. (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex)
  2761.  
  2762. (put 'deftypevr 'texinfo-format 'texinfo-format-defun)
  2763. (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx)
  2764. (put 'deftypevr 'texinfo-end 'texinfo-end-defun)
  2765. (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil))
  2766. (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil))
  2767. (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex)
  2768. (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex)
  2769.  
  2770. (put 'deftypevar 'texinfo-format 'texinfo-format-defun)
  2771. (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx)
  2772. (put 'deftypevar 'texinfo-end 'texinfo-end-defun)
  2773. (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable"))
  2774. (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable"))
  2775. (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex)
  2776. (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex)
  2777.  
  2778.  
  2779. ;;; @set, @clear, @ifset, @ifclear
  2780.  
  2781. ;; If a flag is set with @set FLAG, then text between @ifset and @end
  2782. ;; ifset is formatted normally, but if the flag is cleared with
  2783. ;; @clear FLAG, then the text is not formatted; it is ignored.
  2784.  
  2785. ;; If a flag is cleared with @clear FLAG, then text between @ifclear
  2786. ;; and @end ifclear is formatted normally, but if the flag is set with
  2787. ;; @set FLAG, then the text is not formatted; it is ignored.  @ifclear
  2788. ;; is the opposite of @ifset.
  2789.  
  2790. ;; If a flag is set to a string with @set FLAG, 
  2791. ;; replace  @value{FLAG} with the string.
  2792. ;; If a flag with a value is cleared, 
  2793. ;; @value{FLAG} is invalid, 
  2794. ;; as if there had never been any @set FLAG previously.
  2795.  
  2796. (put 'clear 'texinfo-format 'texinfo-clear)
  2797. (defun texinfo-clear ()
  2798.   "Clear the value of the flag."
  2799.   (let* ((arg (texinfo-parse-arg-discard))
  2800.          (flag (car (read-from-string arg)))
  2801.          (value (substring arg (cdr (read-from-string arg)))))
  2802.     (put flag 'texinfo-whether-setp 'flag-cleared)
  2803.     (put flag 'texinfo-set-value "")))
  2804.  
  2805. (put 'set 'texinfo-format 'texinfo-set)
  2806. (defun texinfo-set ()
  2807.   "Set the value of the flag, optionally to a string.
  2808. The command  `@set foo This is a string.'
  2809. sets flag foo to the value: `This is a string.'
  2810. The command  `@value{foo}'  expands to the value."
  2811.   (let* ((arg (texinfo-parse-arg-discard))
  2812.          (flag (car (read-from-string arg)))
  2813.          (value (substring arg (cdr (read-from-string arg)))))
  2814.     (put flag 'texinfo-whether-setp 'flag-set)
  2815.     (put flag 'texinfo-set-value value)))
  2816.  
  2817. (put 'value 'texinfo-format 'texinfo-value)
  2818. (defun texinfo-value ()
  2819.   "Insert the string to which the flag is set.
  2820. The command  `@set foo This is a string.'
  2821. sets flag foo to the value: `This is a string.'
  2822. The command  `@value{foo}'  expands to the value."
  2823.   (let ((arg (texinfo-parse-arg-discard)))
  2824.     (cond ((and
  2825.             (eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2826.                 'flag-set)
  2827.             (get (car (read-from-string arg)) 'texinfo-set-value))
  2828.            (insert (get (car (read-from-string arg)) 'texinfo-set-value)))
  2829.           ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) 
  2830.                'flag-cleared)
  2831.            (insert (format "{No value for \"%s\"}"  arg)))
  2832.           ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) nil)
  2833.            (insert (format "{No value for \"%s\"}"  arg))))))
  2834.  
  2835. (put 'ifset 'texinfo-end 'texinfo-discard-command)
  2836. (put 'ifset 'texinfo-format 'texinfo-if-set)
  2837. (defun texinfo-if-set ()
  2838.   "If set, continue formatting; else do not format region up to @end ifset"
  2839.   (let ((arg (texinfo-parse-arg-discard)))
  2840.     (cond
  2841.      ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2842.           'flag-set)
  2843.       ;; Format the text (i.e., do not remove it); do nothing here.
  2844.       ())
  2845.      ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2846.           'flag-cleared)
  2847.       ;; Clear region (i.e., cause the text to be ignored).
  2848.       (delete-region texinfo-command-start
  2849.                        (progn (re-search-forward "@end ifset[ \t]*\n")
  2850.                               (point))))
  2851.      ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2852.           nil)
  2853.       ;; In this case flag is neither set nor cleared.  
  2854.       ;; Act as if set, i.e. do nothing.
  2855.       ()))))
  2856.  
  2857. (put 'ifclear 'texinfo-end 'texinfo-discard-command)
  2858. (put 'ifclear 'texinfo-format 'texinfo-if-clear)
  2859. (defun texinfo-if-clear ()
  2860.   "If clear, continue formatting; if set, do not format up to @end ifset"
  2861.   (let ((arg (texinfo-parse-arg-discard)))
  2862.     (cond
  2863.      ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2864.           'flag-set)
  2865.       ;; Clear region (i.e., cause the text to be ignored).
  2866.       (delete-region texinfo-command-start
  2867.                        (progn (re-search-forward "@end ifclear[ \t]*\n")
  2868.                               (point))))
  2869.      ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2870.           'flag-cleared)
  2871.       ;; Format the text (i.e., do not remove it); do nothing here.
  2872.       ())
  2873.      ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  2874.           nil)
  2875.       ;; In this case flag is neither set nor cleared.  
  2876.       ;; Act as if clear, i.e. do nothing.
  2877.       ()))))
  2878.  
  2879.  
  2880. ;;; Process included files:  `@include' command
  2881.  
  2882. ;; Updated 19 October 1990
  2883. ;; In the original version, include files were ignored by Info but
  2884. ;; incorporated in to the printed manual.  To make references to the
  2885. ;; included file, the Texinfo source file has to refer to the included
  2886. ;; files using the `(filename)nodename' format for referring to other
  2887. ;; Info files.  Also, the included files had to be formatted on their
  2888. ;; own.  It was just like they were another file.
  2889.  
  2890. ;; Currently, include files are inserted into the buffer that is
  2891. ;; formatted for Info.  If large, the resulting info file is split and
  2892. ;; tagified.  For current include files to work, the master menu must
  2893. ;; refer to all the nodes, and the highest level nodes in the include
  2894. ;; files must have the correct next, prev, and up pointers.
  2895.  
  2896. ;; The included file may have an @setfilename and even an @settitle,
  2897. ;; but not an `\input texinfo' line.
  2898.  
  2899. ;; Updated 24 March 1993
  2900. ;; In order for @raisesections and @lowersections to work, included
  2901. ;; files must be inserted into the buffer holding the outer file
  2902. ;; before other Info formatting takes place.  So @include is no longer
  2903. ;; is treated like other @-commands.
  2904. (put 'include 'texinfo-format  'texinfo-format-noop)
  2905.  
  2906. ; Original definition:
  2907. ; (defun texinfo-format-include ()
  2908. ;   (let ((filename (texinfo-parse-arg-discard))
  2909. ;       (default-directory input-directory)
  2910. ;       subindex)
  2911. ;     (setq subindex
  2912. ;         (save-excursion
  2913. ;           (progn (find-file
  2914. ;                   (cond ((file-readable-p (concat filename ".texinfo"))
  2915. ;                          (concat filename ".texinfo"))
  2916. ;                         ((file-readable-p (concat filename ".texi"))
  2917. ;                          (concat filename ".texi"))
  2918. ;                         ((file-readable-p (concat filename ".tex"))
  2919. ;                          (concat filename ".tex"))
  2920. ;                         ((file-readable-p filename)
  2921. ;                          filename)
  2922. ;                         (t (error "@include'd file %s not found"
  2923. ;                                   filename))))
  2924. ;                  (texinfo-format-buffer-1))))
  2925. ;     (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
  2926. ;     (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
  2927. ;     (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
  2928. ;     (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
  2929. ;     (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
  2930. ;     (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
  2931. ;
  2932. ;(defun texinfo-subindex (indexvar file content)
  2933. ;  (set indexvar (cons (list 'recurse file content)
  2934. ;                      (symbol-value indexvar))))
  2935.  
  2936. ; Second definition:
  2937. ; (put 'include 'texinfo-format 'texinfo-format-include)
  2938. ; (defun texinfo-format-include ()
  2939. ;   (let ((filename (concat input-directory
  2940. ;                           (texinfo-parse-arg-discard)))
  2941. ;         (default-directory input-directory))
  2942. ;     (message "Reading: %s" filename)
  2943. ;     (save-excursion
  2944. ;       (save-restriction
  2945. ;         (narrow-to-region
  2946. ;          (point)
  2947. ;          (+ (point) (car (cdr (insert-file-contents filename)))))
  2948. ;         (goto-char (point-min))
  2949. ;         (texinfo-append-refill)
  2950. ;         (texinfo-format-convert (point-min) (point-max))))
  2951. ;     (setq last-input-buffer input-buffer)  ; to bypass setfilename
  2952. ;     ))
  2953.  
  2954.  
  2955. ;;; Numerous commands do nothing in Texinfo
  2956.  
  2957. ;; These commands are defined in texinfo.tex for printed output.
  2958.  
  2959. (put 'bye 'texinfo-format 'texinfo-discard-line)
  2960. (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
  2961. (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
  2962. (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
  2963. (put 'finalout 'texinfo-format 'texinfo-discard-line)
  2964. (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
  2965. (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
  2966. (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
  2967. (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
  2968. (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
  2969. (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
  2970. (put 'need 'texinfo-format 'texinfo-discard-line-with-args)
  2971. (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
  2972. (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
  2973. (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
  2974. (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
  2975. (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
  2976. (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
  2977. (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
  2978. (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
  2979. (put 'smallbook 'texinfo-format 'texinfo-discard-line)
  2980. (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
  2981.  
  2982.  
  2983. ;;; Some commands cannot be handled
  2984.  
  2985. (defun texinfo-unsupported ()
  2986.   (error "%s is not handled by texinfo"
  2987.          (buffer-substring texinfo-command-start texinfo-command-end)))
  2988.  
  2989. ;;; Batch formatting
  2990.  
  2991. ;;;###autoload
  2992. (defun batch-texinfo-format ()
  2993.   "Runs  texinfo-format-buffer  on the files remaining on the command line.
  2994. Must be used only with -batch, and kills emacs on completion.
  2995. Each file will be processed even if an error occurred previously.
  2996. For example, invoke
  2997.   \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
  2998.   (if (not noninteractive)
  2999.       (error "batch-texinfo-format may only be used -batch."))
  3000.   (let ((version-control t)
  3001.         (auto-save-default nil)
  3002.         (find-file-run-dired nil)
  3003.         (kept-old-versions 259259)
  3004.         (kept-new-versions 259259))
  3005.     (let ((error 0)
  3006.           file
  3007.           (files ()))
  3008.       (while command-line-args-left
  3009.         (setq file (expand-file-name (car command-line-args-left)))
  3010.         (cond ((not (file-exists-p file))
  3011.                (message ">> %s does not exist!" file)
  3012.                (setq error 1
  3013.                      command-line-args-left (cdr command-line-args-left)))
  3014.               ((file-directory-p file)
  3015.                (setq command-line-args-left
  3016.                      (nconc (directory-files file)
  3017.                             (cdr command-line-args-left))))
  3018.               (t
  3019.                (setq files (cons file files)
  3020.                      command-line-args-left (cdr command-line-args-left)))))
  3021.       (while files
  3022.         (setq file (car files)
  3023.               files (cdr files))
  3024.         (condition-case err
  3025.             (progn
  3026.               (if buffer-file-name (kill-buffer (current-buffer)))
  3027.               (find-file file)
  3028.               (buffer-disable-undo (current-buffer))
  3029.               (set-buffer-modified-p nil)
  3030.               (texinfo-mode)
  3031.               (message "texinfo formatting %s..." file)
  3032.               (texinfo-format-buffer nil)
  3033.               (if (buffer-modified-p)
  3034.                   (progn (message "Saving modified %s" (buffer-file-name))
  3035.                          (save-buffer))))
  3036.           (error
  3037.            (message ">> Error: %s" (prin1-to-string err))
  3038.            (message ">>  point at")
  3039.            (let ((s (buffer-substring (point)
  3040.                                       (min (+ (point) 100)
  3041.                                            (point-max))))
  3042.                  (tem 0))
  3043.              (while (setq tem (string-match "\n+" s tem))
  3044.                (setq s (concat (substring s 0 (match-beginning 0))
  3045.                                "\n>>  "
  3046.                                (substring s (match-end 0)))
  3047.                      tem (1+ tem)))
  3048.              (message ">>  %s" s))
  3049.            (setq error 1))))
  3050.       (kill-emacs error))))
  3051.  
  3052.  
  3053. ;;; Place `provide' at end of file.
  3054. (provide 'texinfmt)
  3055.  
  3056. ;;; texinfmt.el ends here.
  3057.